diff --git a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java index 9bca0e9..7164ab6 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java +++ b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java @@ -4,7 +4,7 @@ * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html - * + * * Contributors: * cpw - initial API and implementation ******************************************************************************/ @@ -41,18 +41,28 @@ import net.minecraft.src.forge.ForgeHooksClient; import net.minecraft.src.forge.IItemRenderer; import net.minecraft.src.forge.MinecraftForgeClient; import cpw.mods.ironchest.IronChestType; +import cpw.mods.ironchest.MappableItemStackWrapper; import cpw.mods.ironchest.TileEntityIronChest; +import cpw.mods.ironchest.mod_IronChest; public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { - private static Map renderList = new HashMap(); + private static Map renderList = new HashMap(); private Random random; private RenderBlocks renderBlocks; - private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F }, { 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, }; - - public static boolean CACHE_RENDER = true; + private static float[][] shifts = { + { 0.3F, 0.45F, 0.3F }, + { 0.7F, 0.45F, 0.3F }, + { 0.3F, 0.45F, 0.7F }, + { 0.7F, 0.45F, 0.7F }, + { 0.3F, 0.1F, 0.3F }, + { 0.7F, 0.1F, 0.3F }, + { 0.3F, 0.1F, 0.7F }, + { 0.7F, 0.1F, 0.7F }, + { 0.5F, 0.32F, 0.5F }, + }; public TileEntityIronChestRenderer() { model = new ModelChest(); @@ -134,7 +144,6 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { shiftY = shifts[shift][1]; shiftZ = shifts[shift][2]; shift++; - IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, IItemRenderer.ItemRenderType.ENTITY); float localScale = blockScale; if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null) { int j = Block.blocksList[item.itemID].getRenderType(); @@ -154,12 +163,14 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { float minishiftZ = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale; glTranslatef(minishiftX, minishiftY, minishiftZ); } - if (renderList.get(item) == null || !CACHE_RENDER) { // Added support for using only old system. - if (CACHE_RENDER) { + MappableItemStackWrapper mis = new MappableItemStackWrapper(item); + if (!mod_IronChest.CACHE_RENDER || !renderList.containsKey(mis)) { // Added support for using only old system. + if (mod_IronChest.CACHE_RENDER) { int render = glGenLists(1); - renderList.put(item, render); + renderList.put(mis, render); glNewList(render, GL_COMPILE_AND_EXECUTE); } + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, IItemRenderer.ItemRenderType.ENTITY); if (customRenderer != null) { customitem.item = item; bindTextureByName("/terrain.png"); @@ -202,12 +213,14 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { tessellator.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10); tessellator.draw(); } - if (CACHE_RENDER) - glEndList(); + if (mod_IronChest.CACHE_RENDER) { + glEndList(); + } } else { - Integer integer = renderList.get(item); - if (integer != null) // Added null check for auto-unboxing JUST in case. + Integer integer = renderList.get(mis); + if (integer != null) { // Added null check for auto-unboxing JUST in case. glCallList(integer.intValue()); + } } glPopMatrix(); } diff --git a/IronChests2/common/cpw/mods/ironchest/MappableItemStackWrapper.java b/IronChests2/common/cpw/mods/ironchest/MappableItemStackWrapper.java new file mode 100644 index 0000000..7dbd810 --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/MappableItemStackWrapper.java @@ -0,0 +1,26 @@ +package cpw.mods.ironchest; + +import net.minecraft.src.ItemStack; + +public class MappableItemStackWrapper { + private ItemStack wrap; + + public MappableItemStackWrapper(ItemStack toWrap) { + wrap=toWrap; + } + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MappableItemStackWrapper)) return false; + MappableItemStackWrapper isw = (MappableItemStackWrapper) obj; + if (wrap.getHasSubtypes()) { + return isw.wrap.isItemEqual(wrap); + } else { + return isw.wrap.itemID == wrap.itemID; + } + } + + @Override + public int hashCode() { + return wrap.itemID; + } +} diff --git a/IronChests2/common/cpw/mods/ironchest/mod_IronChest.java b/IronChests2/common/cpw/mods/ironchest/mod_IronChest.java index 6055d11..f46ed78 100644 --- a/IronChests2/common/cpw/mods/ironchest/mod_IronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/mod_IronChest.java @@ -25,10 +25,10 @@ import net.minecraft.src.forge.NetworkMod; public class mod_IronChest extends NetworkMod { public static BlockIronChest ironChestBlock; - public static ItemChestChanger itemChestChanger; @SidedProxy(clientSide="cpw.mods.ironchest.client.ClientProxy", serverSide="cpw.mods.ironchest.server.ServerProxy") public static IProxy proxy; public static mod_IronChest instance; + public static boolean CACHE_RENDER = true; @Override public String getVersion() { @@ -50,6 +50,7 @@ public class mod_IronChest extends NetworkMod { int bId = cfg.getOrCreateBlockIdProperty("ironChests", 181).getInt(181); ironChestBlock = new BlockIronChest(bId); ChestChangerType.buildItems(cfg, 29501); + CACHE_RENDER = cfg.getOrCreateBooleanProperty("cacheRenderingInformation", Configuration.CATEGORY_GENERAL, true).getBoolean(true); } catch (Exception e) { ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully"); e.printStackTrace(System.err); @@ -85,6 +86,8 @@ public class mod_IronChest extends NetworkMod { 2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6 + 8 /* crystal chest */ }; for (IronChestType icType : IronChestType.values()) { + if (icType.ordinal()>=chestEMCValues.length) + break; addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]); } addMeta.invoke(null, ironChestBlock.blockID, IronChestType.values().length - 1);