Search in sources :

Example 1 with IRegistryDelegate

use of net.minecraftforge.registries.IRegistryDelegate in project Random-Things by lumien231.

the class PortKeyMesh method getModelLocation.

@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
    NBTTagCompound camo = stack.getSubCompound("camo");
    if (camo != null) {
        ItemStack camoStack = new ItemStack(camo.getCompoundTag("stack"));
        Item item = camoStack.getItem();
        int meta = camoStack.getItemDamage();
        Map<IRegistryDelegate<Item>, TIntObjectHashMap<ModelResourceLocation>> modelMap = ReflectionUtil.getModelMap();
        if (modelMap != null && modelMap.containsKey(item.delegate)) {
            TIntObjectHashMap<ModelResourceLocation> metaMap = modelMap.get(item.delegate);
            if (metaMap.contains(meta)) {
                return metaMap.get(meta);
            }
        }
    }
    return new ModelResourceLocation("randomthings:portkey");
}
Also used : Item(net.minecraft.item.Item) IRegistryDelegate(net.minecraftforge.registries.IRegistryDelegate) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IRegistryDelegate

use of net.minecraftforge.registries.IRegistryDelegate in project FoamFix by asiekierka.

the class FoamFixModelRegistryDuplicateWipe method onTextureStitchPost.

@SubscribeEvent
public void onTextureStitchPost(TextureStitchEvent.Post event) {
    ItemModelMesher imm = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
    BlockModelShapes bms = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
    ModelManager mgr = bms.getModelManager();
    Field f = ReflectionHelper.findField(ModelManager.class, "modelRegistry", "field_174958_a");
    try {
        IRegistry<ModelResourceLocation, IBakedModel> registry = (IRegistry<ModelResourceLocation, IBakedModel>) f.get(mgr);
        FoamFix.logger.info("Clearing unnecessary model registry of size " + registry.getKeys().size() + ".");
        for (ModelResourceLocation l : registry.getKeys()) {
            registry.putObject(l, ProxyClient.DUMMY_MODEL);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    f = ReflectionHelper.findField(BlockModelShapes.class, "bakedModelStore", "field_178129_a");
    try {
        Map<IBlockState, IBakedModel> modelStore = (Map<IBlockState, IBakedModel>) f.get(bms);
        FoamFix.logger.info("Clearing unnecessary model store of size " + modelStore.size() + ".");
        modelStore.clear();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (imm instanceof ItemModelMesherForge) {
        f = ReflectionHelper.findField(ItemModelMesherForge.class, "models");
        try {
            Map<IRegistryDelegate<Item>, TIntObjectHashMap<IBakedModel>> modelStore = (Map<IRegistryDelegate<Item>, TIntObjectHashMap<IBakedModel>>) f.get(imm);
            FoamFix.logger.info("Clearing unnecessary item shapes cache of size " + modelStore.size() + ".");
            modelStore.clear();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelManager(net.minecraft.client.renderer.block.model.ModelManager) BlockModelShapes(net.minecraft.client.renderer.BlockModelShapes) Field(java.lang.reflect.Field) Item(net.minecraft.item.Item) ItemModelMesher(net.minecraft.client.renderer.ItemModelMesher) IRegistryDelegate(net.minecraftforge.registries.IRegistryDelegate) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemModelMesherForge(net.minecraftforge.client.ItemModelMesherForge) IRegistry(net.minecraft.util.registry.IRegistry) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)2 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 Item (net.minecraft.item.Item)2 IRegistryDelegate (net.minecraftforge.registries.IRegistryDelegate)2 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockModelShapes (net.minecraft.client.renderer.BlockModelShapes)1 ItemModelMesher (net.minecraft.client.renderer.ItemModelMesher)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 ModelManager (net.minecraft.client.renderer.block.model.ModelManager)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 IRegistry (net.minecraft.util.registry.IRegistry)1 ItemModelMesherForge (net.minecraftforge.client.ItemModelMesherForge)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1