Tweak the caching patch to remember items properly, so it doesn't regenerate for every item stack that comes in

This commit is contained in:
Christian 2012-07-08 14:28:25 -04:00
parent 887ac8a216
commit 500a7aa212
3 changed files with 56 additions and 14 deletions

View File

@ -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<ItemStack, Integer> renderList = new HashMap<ItemStack, Integer>();
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
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();
}

View File

@ -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;
}
}

View File

@ -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);