mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 00:07:45 +00:00
Add function to lookup model location for an ItemStack (#5017)
This commit is contained in:
1 parent
14bfeefb4d
commit
f3f1e585dc
2 files changed
+42
No files matched your search
@@ -26,13 +26,19 @@ import com.google.common.collect.Maps;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.registries.IRegistryDelegate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Wrapper around ItemModeMesher that cleans up the internal maps to respect ID remapping.
|
||||
*/
|
||||
@@ -47,6 +53,7 @@ public class ItemModelMesherForge extends ItemModelMesher
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected IBakedModel getItemModel(Item item, int meta)
|
||||
{
|
||||
Int2ObjectMap<IBakedModel> map = models.get(item.delegate);
|
||||
@@ -95,4 +102,32 @@ public class ItemModelMesherForge extends ItemModelMesher
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public ModelResourceLocation getLocation(@Nonnull ItemStack stack)
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
ModelResourceLocation location = null;
|
||||
|
||||
Int2ObjectMap<ModelResourceLocation> map = locations.get(item.delegate);
|
||||
if (map != null)
|
||||
{
|
||||
location = map.get(getMetadata(stack));
|
||||
}
|
||||
|
||||
if (location == null)
|
||||
{
|
||||
ItemMeshDefinition definition = shapers.get(item);
|
||||
if (definition != null)
|
||||
{
|
||||
location = definition.getModelLocation(stack);
|
||||
}
|
||||
}
|
||||
|
||||
if (location == null)
|
||||
{
|
||||
location = ModelBakery.MODEL_MISSING;
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user