Untie ItemModelMesher from using Item Ids internally by implementing our own simple mechanics using Trove.
This commit is contained in:
parent
ecd4a259ec
commit
0b41756125
2 changed files with 91 additions and 0 deletions
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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<Item, TIntObjectHashMap<ModelResourceLocation>> locations = Maps.newIdentityHashMap();
|
||||
IdentityHashMap<Item, TIntObjectHashMap<IBakedModel>> models = Maps.newIdentityHashMap();
|
||||
|
||||
public ItemModelMesherForge(ModelManager manager)
|
||||
{
|
||||
super(manager);
|
||||
}
|
||||
|
||||
protected IBakedModel getItemModel(Item item, int meta)
|
||||
{
|
||||
TIntObjectHashMap<IBakedModel> map = models.get(item);
|
||||
return map == null ? null : map.get(meta);
|
||||
}
|
||||
|
||||
public void register(Item item, int meta, ModelResourceLocation location)
|
||||
{
|
||||
TIntObjectHashMap<ModelResourceLocation> locs = locations.get(item);
|
||||
TIntObjectHashMap<IBakedModel> 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<Item, TIntObjectHashMap<ModelResourceLocation>> e : locations.entrySet())
|
||||
{
|
||||
TIntObjectHashMap<IBakedModel> mods = models.get(e.getKey());
|
||||
if (mods != null)
|
||||
{
|
||||
mods.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mods = new TIntObjectHashMap();
|
||||
models.put(e.getKey(), mods);
|
||||
}
|
||||
final TIntObjectHashMap<IBakedModel> map = mods;
|
||||
e.getValue().forEachEntry(new TIntObjectProcedure<ModelResourceLocation>()
|
||||
{
|
||||
@Override
|
||||
public boolean execute(int meta, ModelResourceLocation location)
|
||||
{
|
||||
map.put(meta, manager.getModel(location));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue