From 0eb7180fc1f52ace4612b7f06a6b075b2ab4e5ec Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 2 Sep 2012 12:39:06 -0400 Subject: [PATCH] Fix out of range entity id handling for ModLoader mods a bit more. Thanks Herobrine mod! --- .../fml/common/registry/EntityRegistry.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/common/cpw/mods/fml/common/registry/EntityRegistry.java b/common/cpw/mods/fml/common/registry/EntityRegistry.java index 544e1cb65c..bf9d90cb02 100644 --- a/common/cpw/mods/fml/common/registry/EntityRegistry.java +++ b/common/cpw/mods/fml/common/registry/EntityRegistry.java @@ -21,6 +21,8 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Maps; +import com.google.common.primitives.UnsignedBytes; +import com.google.common.primitives.UnsignedInteger; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; @@ -179,16 +181,32 @@ public class EntityRegistry private int validateAndClaimId(int id) { // workaround for broken ML - if (id < 0) + int realId = id; + if (id < Byte.MIN_VALUE) { - id += 3000; + FMLLog.warning("Compensating for modloader out of range compensation by mod : entityId %d for mod %s is now %d", id, Loader.instance().activeModContainer().getModId(), realId); + realId += 3000; } - if (!availableIndicies.get(id)) + + if (realId < 0) + { + realId += Byte.MAX_VALUE; + } + try + { + UnsignedBytes.checkedCast(realId); + } + catch (IllegalArgumentException e) + { + FMLLog.log(Level.SEVERE, "The entity ID %d for mod %s is not an unsigned byte and may not work", id, Loader.instance().activeModContainer().getModId()); + } + + if (!availableIndicies.get(realId)) { FMLLog.severe("The mod %s has attempted to register an entity ID %d which is already reserved. This could cause severe problems", Loader.instance().activeModContainer().getModId(), id); } - availableIndicies.clear(id); - return id; + availableIndicies.clear(realId); + return realId; } public static void registerGlobalEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour)