From 0b417561253171a70a8a33db933e1684a43d0ecf Mon Sep 17 00:00:00 2001 From: Lex Manos Date: Fri, 12 Dec 2014 11:47:27 -0800 Subject: [PATCH] Untie ItemModelMesher from using Item Ids internally by implementing our own simple mechanics using Trove. --- .../renderer/entity/RenderItem.java.patch | 9 ++ .../client/ItemModelMesherForge.java | 82 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/main/java/net/minecraftforge/client/ItemModelMesherForge.java diff --git a/patches/minecraft/net/minecraft/client/renderer/entity/RenderItem.java.patch b/patches/minecraft/net/minecraft/client/renderer/entity/RenderItem.java.patch index 321f6b146..7c47255b8 100644 --- a/patches/minecraft/net/minecraft/client/renderer/entity/RenderItem.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/entity/RenderItem.java.patch @@ -1,5 +1,14 @@ --- ../src-base/minecraft/net/minecraft/client/renderer/entity/RenderItem.java +++ ../src-work/minecraft/net/minecraft/client/renderer/entity/RenderItem.java +@@ -83,7 +83,7 @@ + public RenderItem(TextureManager p_i46165_1_, ModelManager p_i46165_2_) + { + this.field_175057_n = p_i46165_1_; +- this.field_175059_m = new ItemModelMesher(p_i46165_2_); ++ this.field_175059_m = new net.minecraftforge.client.ItemModelMesherForge(p_i46165_2_); + this.func_175041_b(); + } + @@ -302,6 +302,10 @@ modelresourcelocation = new ModelResourceLocation("bow_pulling_0", "inventory"); } diff --git a/src/main/java/net/minecraftforge/client/ItemModelMesherForge.java b/src/main/java/net/minecraftforge/client/ItemModelMesherForge.java new file mode 100644 index 000000000..9966c2346 --- /dev/null +++ b/src/main/java/net/minecraftforge/client/ItemModelMesherForge.java @@ -0,0 +1,82 @@ +package net.minecraftforge.client; + +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import com.google.common.collect.Maps; + +import gnu.trove.map.hash.TIntObjectHashMap; +import gnu.trove.procedure.TIntObjectProcedure; +import net.minecraft.client.renderer.ItemModelMesher; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.client.resources.model.ModelManager; +import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.item.Item; + +/** + * Wrapper around ItemModeMesher that cleans up the internal maps to respect ID remapping. + */ +public class ItemModelMesherForge extends ItemModelMesher +{ + IdentityHashMap> locations = Maps.newIdentityHashMap(); + IdentityHashMap> models = Maps.newIdentityHashMap(); + + public ItemModelMesherForge(ModelManager manager) + { + super(manager); + } + + protected IBakedModel getItemModel(Item item, int meta) + { + TIntObjectHashMap map = models.get(item); + return map == null ? null : map.get(meta); + } + + public void register(Item item, int meta, ModelResourceLocation location) + { + TIntObjectHashMap locs = locations.get(item); + TIntObjectHashMap mods = models.get(item); + if (locs == null) + { + locs = new TIntObjectHashMap(); + locations.put(item, locs); + } + if (mods == null) + { + mods = new TIntObjectHashMap(); + models.put(item, mods); + } + locs.put(meta, location); + mods.put(meta, getModelManager().getModel(location)); + } + + public void rebuildCache() + { + final ModelManager manager = this.getModelManager(); + for (Map.Entry> e : locations.entrySet()) + { + TIntObjectHashMap mods = models.get(e.getKey()); + if (mods != null) + { + mods.clear(); + } + else + { + mods = new TIntObjectHashMap(); + models.put(e.getKey(), mods); + } + final TIntObjectHashMap map = mods; + e.getValue().forEachEntry(new TIntObjectProcedure() + { + @Override + public boolean execute(int meta, ModelResourceLocation location) + { + map.put(meta, manager.getModel(location)); + return true; + } + }); + } + } +}