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:
parent
887ac8a216
commit
500a7aa212
|
@ -4,7 +4,7 @@
|
||||||
* are made available under the terms of the GNU Public License v3.0
|
* are made available under the terms of the GNU Public License v3.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.gnu.org/licenses/gpl.html
|
* http://www.gnu.org/licenses/gpl.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* cpw - initial API and implementation
|
* 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.IItemRenderer;
|
||||||
import net.minecraft.src.forge.MinecraftForgeClient;
|
import net.minecraft.src.forge.MinecraftForgeClient;
|
||||||
import cpw.mods.ironchest.IronChestType;
|
import cpw.mods.ironchest.IronChestType;
|
||||||
|
import cpw.mods.ironchest.MappableItemStackWrapper;
|
||||||
import cpw.mods.ironchest.TileEntityIronChest;
|
import cpw.mods.ironchest.TileEntityIronChest;
|
||||||
|
import cpw.mods.ironchest.mod_IronChest;
|
||||||
|
|
||||||
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
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 Random random;
|
||||||
|
|
||||||
private RenderBlocks renderBlocks;
|
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 }, };
|
private static float[][] shifts = {
|
||||||
|
{ 0.3F, 0.45F, 0.3F },
|
||||||
public static boolean CACHE_RENDER = true;
|
{ 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() {
|
public TileEntityIronChestRenderer() {
|
||||||
model = new ModelChest();
|
model = new ModelChest();
|
||||||
|
@ -134,7 +144,6 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
||||||
shiftY = shifts[shift][1];
|
shiftY = shifts[shift][1];
|
||||||
shiftZ = shifts[shift][2];
|
shiftZ = shifts[shift][2];
|
||||||
shift++;
|
shift++;
|
||||||
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, IItemRenderer.ItemRenderType.ENTITY);
|
|
||||||
float localScale = blockScale;
|
float localScale = blockScale;
|
||||||
if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null) {
|
if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null) {
|
||||||
int j = Block.blocksList[item.itemID].getRenderType();
|
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;
|
float minishiftZ = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
|
||||||
glTranslatef(minishiftX, minishiftY, minishiftZ);
|
glTranslatef(minishiftX, minishiftY, minishiftZ);
|
||||||
}
|
}
|
||||||
if (renderList.get(item) == null || !CACHE_RENDER) { // Added support for using only old system.
|
MappableItemStackWrapper mis = new MappableItemStackWrapper(item);
|
||||||
if (CACHE_RENDER) {
|
if (!mod_IronChest.CACHE_RENDER || !renderList.containsKey(mis)) { // Added support for using only old system.
|
||||||
|
if (mod_IronChest.CACHE_RENDER) {
|
||||||
int render = glGenLists(1);
|
int render = glGenLists(1);
|
||||||
renderList.put(item, render);
|
renderList.put(mis, render);
|
||||||
glNewList(render, GL_COMPILE_AND_EXECUTE);
|
glNewList(render, GL_COMPILE_AND_EXECUTE);
|
||||||
}
|
}
|
||||||
|
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, IItemRenderer.ItemRenderType.ENTITY);
|
||||||
if (customRenderer != null) {
|
if (customRenderer != null) {
|
||||||
customitem.item = item;
|
customitem.item = item;
|
||||||
bindTextureByName("/terrain.png");
|
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.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10);
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
if (CACHE_RENDER)
|
if (mod_IronChest.CACHE_RENDER) {
|
||||||
glEndList();
|
glEndList();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Integer integer = renderList.get(item);
|
Integer integer = renderList.get(mis);
|
||||||
if (integer != null) // Added null check for auto-unboxing JUST in case.
|
if (integer != null) { // Added null check for auto-unboxing JUST in case.
|
||||||
glCallList(integer.intValue());
|
glCallList(integer.intValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,10 +25,10 @@ import net.minecraft.src.forge.NetworkMod;
|
||||||
public class mod_IronChest extends NetworkMod {
|
public class mod_IronChest extends NetworkMod {
|
||||||
|
|
||||||
public static BlockIronChest ironChestBlock;
|
public static BlockIronChest ironChestBlock;
|
||||||
public static ItemChestChanger itemChestChanger;
|
|
||||||
@SidedProxy(clientSide="cpw.mods.ironchest.client.ClientProxy", serverSide="cpw.mods.ironchest.server.ServerProxy")
|
@SidedProxy(clientSide="cpw.mods.ironchest.client.ClientProxy", serverSide="cpw.mods.ironchest.server.ServerProxy")
|
||||||
public static IProxy proxy;
|
public static IProxy proxy;
|
||||||
public static mod_IronChest instance;
|
public static mod_IronChest instance;
|
||||||
|
public static boolean CACHE_RENDER = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
|
@ -50,6 +50,7 @@ public class mod_IronChest extends NetworkMod {
|
||||||
int bId = cfg.getOrCreateBlockIdProperty("ironChests", 181).getInt(181);
|
int bId = cfg.getOrCreateBlockIdProperty("ironChests", 181).getInt(181);
|
||||||
ironChestBlock = new BlockIronChest(bId);
|
ironChestBlock = new BlockIronChest(bId);
|
||||||
ChestChangerType.buildItems(cfg, 29501);
|
ChestChangerType.buildItems(cfg, 29501);
|
||||||
|
CACHE_RENDER = cfg.getOrCreateBooleanProperty("cacheRenderingInformation", Configuration.CATEGORY_GENERAL, true).getBoolean(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully");
|
ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully");
|
||||||
e.printStackTrace(System.err);
|
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 */
|
2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6 + 8 /* crystal chest */
|
||||||
};
|
};
|
||||||
for (IronChestType icType : IronChestType.values()) {
|
for (IronChestType icType : IronChestType.values()) {
|
||||||
|
if (icType.ordinal()>=chestEMCValues.length)
|
||||||
|
break;
|
||||||
addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]);
|
addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]);
|
||||||
}
|
}
|
||||||
addMeta.invoke(null, ironChestBlock.blockID, IronChestType.values().length - 1);
|
addMeta.invoke(null, ironChestBlock.blockID, IronChestType.values().length - 1);
|
||||||
|
|
Loading…
Reference in New Issue