Beispiel #1
0
 public static void registerEntityClass(Class<?> clazz) {
   if (ENTITY_CLASS_TO_INT == null || ENTITY_CLASS_TO_INT.containsKey(clazz)) return;
   Class<?> search = clazz;
   while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
     if (!ENTITY_CLASS_TO_INT.containsKey(search)) continue;
     int code = ENTITY_CLASS_TO_INT.get(search);
     ENTITY_CLASS_TO_INT.put(clazz, code);
     ENTITY_CLASS_TO_NAME.put(clazz, ENTITY_CLASS_TO_NAME.get(search));
     return;
   }
   throw new IllegalArgumentException(
       "unable to find valid entity superclass for class " + clazz.toString());
 }
Beispiel #2
0
 private static Constructor<?> getCustomEntityConstructor(Class<?> clazz, EntityType type)
     throws SecurityException, NoSuchMethodException {
   Constructor<?> constructor = ENTITY_CONSTRUCTOR_CACHE.get(clazz);
   if (constructor == null) {
     constructor = clazz.getConstructor(World.class);
     constructor.setAccessible(true);
     ENTITY_CLASS_TO_INT.put(clazz, (int) type.getTypeId());
     ENTITY_CONSTRUCTOR_CACHE.put(clazz, constructor);
   }
   return constructor;
 }