From c349d519235ab2cb94186c367c423c27f8473f54 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 21 Aug 2012 19:34:33 -0400 Subject: [PATCH] Automatic mod entity registration into the global entity list. This might break entity code out there, sorry, but this way for most entities you no longer need to manage the global mod entity stuff at all. just remove it. FML will take care of the rest (note, worlds won't load the old entities) --- .../fml/common/registry/EntityRegistry.java | 17 +++++++++++++++++ common/fml_at.cfg | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/common/cpw/mods/fml/common/registry/EntityRegistry.java b/common/cpw/mods/fml/common/registry/EntityRegistry.java index 4d6f1a9474..ce4994ef7e 100644 --- a/common/cpw/mods/fml/common/registry/EntityRegistry.java +++ b/common/cpw/mods/fml/common/registry/EntityRegistry.java @@ -22,6 +22,7 @@ import com.google.common.collect.Maps; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; public class EntityRegistry @@ -124,6 +125,17 @@ public class EntityRegistry { entityClassRegistrations.put(entityClass, er); entityNames.put(entityName, mc); + if (!EntityList.field_75626_c.containsKey(entityClass)) + { + String entityModName = String.format("%s.%s", mc.getModId(), entityName); + EntityList.field_75626_c.put(entityClass, entityModName); + EntityList.field_75625_b.put(entityModName, entityClass); + FMLLog.finest("Automatically registered mod %s entity %s as %s", mc.getModId(), entityName, entityModName); + } + else + { + FMLLog.fine("Skipping automatic mod %s entity registration for already registered class %s", mc.getModId(), entityClass.getName()); + } } catch (IllegalArgumentException e) { @@ -135,6 +147,11 @@ public class EntityRegistry public static void registerGlobalEntityID(Class entityClass, String entityName, int id) { + if (EntityList.field_75626_c.containsKey(entityClass)) + { + FMLLog.warning("The mod %s tried to register the entity class %s which was already registered - if you wish to override default naming for FML mod entities, register it here first", Loader.instance().activeModContainer().getModId(), entityClass); + return; + } instance().validateAndClaimId(id); EntityList.func_75618_a(entityClass, entityName, id); } diff --git a/common/fml_at.cfg b/common/fml_at.cfg index 9fd573ae51..5eee78f224 100644 --- a/common/fml_at.cfg +++ b/common/fml_at.cfg @@ -4,9 +4,10 @@ public aji.a(Ljava/lang/Class;Ljava/lang/String;)V # EntityList addMappings public jr.a(Ljava/lang/Class;Ljava/lang/String;I)V public jr.a(Ljava/lang/Class;Ljava/lang/String;III)V -# EntityList nameToClassMap and idToClassMap +# EntityList nameToClassMap and idToClassMap and classToNameMap public jr.b public jr.d +public jr.c # RenderEngine public avf.k # texturePack # RenderManager renderers