Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public void registerEntityType(
      MyPetType type, Class<? extends MyPetMinecraftEntity> entityClass) {
    try {
      Field EntityTypes_d = ReflectionUtil.getField(EntityTypes.class, "d");
      Field EntityTypes_f = ReflectionUtil.getField(EntityTypes.class, "f");

      Map<Class, String> d = (Map) EntityTypes_d.get(EntityTypes_d);
      Map<Class, Integer> f = (Map) EntityTypes_f.get(EntityTypes_f);

      Iterator cIterator = d.keySet().iterator();
      while (cIterator.hasNext()) {
        Class clazz = (Class) cIterator.next();
        if (clazz.getCanonicalName().equals(entityClass.getCanonicalName())) {
          cIterator.remove();
        }
      }

      Iterator eIterator = f.keySet().iterator();
      while (eIterator.hasNext()) {
        Class clazz = (Class) eIterator.next();
        if (clazz.getCanonicalName().equals(entityClass.getCanonicalName())) {
          eIterator.remove();
        }
      }

      d.put(entityClass, type.getMinecraftName());
      f.put(entityClass, type.getTypeID());

    } catch (Exception e) {
      MyPetApi.getLogger().warning("Error while registering " + entityClass.getCanonicalName());
    }
  }
Ejemplo n.º 2
0
 public static MyPetClass getByMyPetType(MyPetType type) {
   return valueOf(type.name());
 }