Search in sources :

Example 1 with ItemMeshDefinition

use of net.minecraft.client.renderer.ItemMeshDefinition in project MinecraftForge by MinecraftForge.

the class ModelLoader method setBucketModelDefinition.

/**
     * Helper method for registering all itemstacks for given item to map to universal bucket model.
     */
public static void setBucketModelDefinition(Item item) {
    ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {

        @Override
        public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) {
            return ModelDynBucket.LOCATION;
        }
    });
    ModelBakery.registerItemVariants(item, ModelDynBucket.LOCATION);
}
Also used : ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemMeshDefinition

use of net.minecraft.client.renderer.ItemMeshDefinition in project ImmersiveEngineering by BluSunrize.

the class ClientProxy method preInitEnd.

@Override
public void preInitEnd() {
    //Going through registered stuff at the end of preInit, because of compat modules possibly adding items
    for (Block block : IEContent.registeredIEBlocks) {
        Item blockItem = Item.getItemFromBlock(block);
        final ResourceLocation loc = GameData.getBlockRegistry().getNameForObject(block);
        if (block instanceof IIEMetaBlock) {
            IIEMetaBlock ieMetaBlock = (IIEMetaBlock) block;
            if (ieMetaBlock.useCustomStateMapper())
                ModelLoader.setCustomStateMapper(block, IECustomStateMapper.getStateMapper(ieMetaBlock));
            ModelLoader.setCustomMeshDefinition(blockItem, new ItemMeshDefinition() {

                @Override
                public ModelResourceLocation getModelLocation(ItemStack stack) {
                    return new ModelResourceLocation(loc, "inventory");
                }
            });
            for (int meta = 0; meta < ieMetaBlock.getMetaEnums().length; meta++) {
                String location = loc.toString();
                String prop = ieMetaBlock.appendPropertiesToState() ? ("inventory," + ieMetaBlock.getMetaProperty().getName() + "=" + ieMetaBlock.getMetaEnums()[meta].toString().toLowerCase(Locale.US)) : null;
                if (ieMetaBlock.useCustomStateMapper()) {
                    String custom = ieMetaBlock.getCustomStateMapping(meta, true);
                    if (custom != null)
                        location += "_" + custom;
                }
                try {
                    ModelLoader.setCustomModelResourceLocation(blockItem, meta, new ModelResourceLocation(location, prop));
                } catch (NullPointerException npe) {
                    throw new RuntimeException("WELP! apparently " + ieMetaBlock + " lacks an item!", npe);
                }
            }
        } else if (block instanceof BlockIEFluid)
            mapFluidState(block, ((BlockIEFluid) block).getFluid());
        else
            ModelLoader.setCustomModelResourceLocation(blockItem, 0, new ModelResourceLocation(loc, "inventory"));
    }
    for (Item item : IEContent.registeredIEItems) {
        if (item instanceof ItemIEBase) {
            ItemIEBase ieMetaItem = (ItemIEBase) item;
            if (ieMetaItem.registerSubModels && ieMetaItem.getSubNames() != null && ieMetaItem.getSubNames().length > 0) {
                for (int meta = 0; meta < ieMetaItem.getSubNames().length; meta++) {
                    ResourceLocation loc = new ResourceLocation("immersiveengineering", ieMetaItem.itemName + "/" + ieMetaItem.getSubNames()[meta]);
                    ModelBakery.registerItemVariants(ieMetaItem, loc);
                    ModelLoader.setCustomModelResourceLocation(ieMetaItem, meta, new ModelResourceLocation(loc, "inventory"));
                }
            } else {
                final ResourceLocation loc = new ResourceLocation("immersiveengineering", ieMetaItem.itemName);
                ModelBakery.registerItemVariants(ieMetaItem, loc);
                ModelLoader.setCustomMeshDefinition(ieMetaItem, new ItemMeshDefinition() {

                    @Override
                    public ModelResourceLocation getModelLocation(ItemStack stack) {
                        return new ModelResourceLocation(loc, "inventory");
                    }
                });
            }
        } else {
            final ResourceLocation loc = GameData.getItemRegistry().getNameForObject(item);
            ModelBakery.registerItemVariants(item, loc);
            ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {

                @Override
                public ModelResourceLocation getModelLocation(ItemStack stack) {
                    return new ModelResourceLocation(loc, "inventory");
                }
            });
        }
    }
    for (IECompatModule compat : IECompatModule.modules) try {
        compat.clientPreInit();
    } catch (Exception exception) {
        IELogger.error("Compat module for " + compat + " could not be client pre-initialized");
    }
}
Also used : BlockIEFluid(blusunrize.immersiveengineering.common.blocks.BlockIEFluid) IIEMetaBlock(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock) IECompatModule(blusunrize.immersiveengineering.common.util.compat.IECompatModule) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IOException(java.io.IOException) ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) IGuiItem(blusunrize.immersiveengineering.common.items.IEItemInterfaces.IGuiItem) IColouredItem(blusunrize.immersiveengineering.common.items.IEItemInterfaces.IColouredItem) Item(net.minecraft.item.Item) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Block(net.minecraft.block.Block) IColouredBlock(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IColouredBlock) IIEMetaBlock(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock) ItemStack(net.minecraft.item.ItemStack) PositionedItemStack(blusunrize.lib.manual.ManualPages.PositionedItemStack)

Example 3 with ItemMeshDefinition

use of net.minecraft.client.renderer.ItemMeshDefinition in project TechReborn by TechReborn.

the class FluidBlockModelHandler method registerFluidBlockModel.

private static void registerFluidBlockModel(BlockFluidTechReborn block) {
    String name = block.getUnlocalizedName().substring(5).toLowerCase();
    Item item = Item.getItemFromBlock(block);
    ModelResourceLocation location = new ModelResourceLocation(new ResourceLocation(ModInfo.MOD_ID.toLowerCase(), "fluids"), name);
    ModelLoader.registerItemVariants(item);
    ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {

        @Override
        public ModelResourceLocation getModelLocation(ItemStack stack) {
            return location;
        }
    });
    ModelLoader.setCustomStateMapper(block, new StateMapperBase() {

        @Override
        protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
            return location;
        }
    });
}
Also used : ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ItemMeshDefinition

use of net.minecraft.client.renderer.ItemMeshDefinition in project Immersive-Tech by FerroO2000.

the class ClientProxy method registerModels.

/**
 * @author BluSunrize
 */
@SubscribeEvent
public static void registerModels(ModelRegistryEvent evt) {
    WireApi.registerConnectorForRender("conn_timer", new ResourceLocation("immersivetech:block/connector/connectors_timer.obj.ie"), null);
    for (Block block : ITContent.registeredITBlocks) {
        final ResourceLocation loc = Block.REGISTRY.getNameForObject(block);
        Item blockItem = Item.getItemFromBlock(block);
        if (blockItem == null)
            throw new RuntimeException("ITEMBLOCK FOR " + loc + " : " + block + " IS NULL");
        if (block instanceof IIEMetaBlock) {
            IIEMetaBlock ieMetaBlock = (IIEMetaBlock) block;
            if (ieMetaBlock.useCustomStateMapper())
                ModelLoader.setCustomStateMapper(block, IECustomStateMapper.getStateMapper(ieMetaBlock));
            ModelLoader.setCustomMeshDefinition(blockItem, new ItemMeshDefinition() {

                @Override
                public ModelResourceLocation getModelLocation(ItemStack stack) {
                    return new ModelResourceLocation(loc, "inventory");
                }
            });
            for (int meta = 0; meta < ieMetaBlock.getMetaEnums().length; meta++) {
                String location = loc.toString();
                String prop = ieMetaBlock.appendPropertiesToState() ? ("inventory," + ieMetaBlock.getMetaProperty().getName() + "=" + ieMetaBlock.getMetaEnums()[meta].toString().toLowerCase(Locale.US)) : null;
                if (ieMetaBlock.useCustomStateMapper()) {
                    String custom = ieMetaBlock.getCustomStateMapping(meta, true);
                    if (custom != null)
                        location += "_" + custom;
                }
                try {
                    ModelLoader.setCustomModelResourceLocation(blockItem, meta, new ModelResourceLocation(location, prop));
                } catch (NullPointerException npe) {
                    throw new RuntimeException("WELP! apparently " + ieMetaBlock + " lacks an item!", npe);
                }
            }
        } else if (block instanceof BlockITFluid)
            mapFluidState(block, ((BlockITFluid) block).getFluid());
        else
            ModelLoader.setCustomModelResourceLocation(blockItem, 0, new ModelResourceLocation(loc, "inventory"));
    }
    for (Item item : ITContent.registeredITItems) {
        if (item instanceof ItemBlock)
            continue;
        if (item instanceof ItemITBase) {
            ItemITBase ipMetaItem = (ItemITBase) item;
            if (ipMetaItem.registerSubModels && ipMetaItem.getSubNames() != null && ipMetaItem.getSubNames().length > 0) {
                for (int meta = 0; meta < ipMetaItem.getSubNames().length; meta++) {
                    ResourceLocation loc = new ResourceLocation(ImmersiveTech.MODID, ipMetaItem.itemName + "/" + ipMetaItem.getSubNames()[meta]);
                    ModelBakery.registerItemVariants(ipMetaItem, loc);
                    ModelLoader.setCustomModelResourceLocation(ipMetaItem, meta, new ModelResourceLocation(loc, "inventory"));
                }
            } else {
                final ResourceLocation loc = new ResourceLocation(ImmersiveTech.MODID, ipMetaItem.itemName);
                ModelBakery.registerItemVariants(ipMetaItem, loc);
                ModelLoader.setCustomMeshDefinition(ipMetaItem, new ItemMeshDefinition() {

                    @Override
                    public ModelResourceLocation getModelLocation(ItemStack stack) {
                        return new ModelResourceLocation(loc, "inventory");
                    }
                });
            }
        } else {
            final ResourceLocation loc = Item.REGISTRY.getNameForObject(item);
            ModelBakery.registerItemVariants(item, loc);
            ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {

                @Override
                public ModelResourceLocation getModelLocation(ItemStack stack) {
                    return new ModelResourceLocation(loc, "inventory");
                }
            });
        }
    }
}
Also used : IIEMetaBlock(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemBlock(net.minecraft.item.ItemBlock) ItemITBase(ferro2000.immersivetech.common.items.ItemITBase) ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) Item(net.minecraft.item.Item) BlockITFluid(ferro2000.immersivetech.common.blocks.BlockITFluid) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) IIEMetaBlock(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with ItemMeshDefinition

use of net.minecraft.client.renderer.ItemMeshDefinition in project Ceramics by KnightMiner.

the class ClientProxy method registerItemModel.

private void registerItemModel(Item item, final String variant) {
    if (item != null && item != Items.AIR) {
        final ResourceLocation location = item.getRegistryName();
        // so all meta get the item model
        ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {

            @Nonnull
            @Override
            public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) {
                return new ModelResourceLocation(location, variant);
            }
        });
        ModelLoader.registerItemVariants(item, location);
    }
}
Also used : ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) Nonnull(javax.annotation.Nonnull) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemMeshDefinition (net.minecraft.client.renderer.ItemMeshDefinition)16 ItemStack (net.minecraft.item.ItemStack)15 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)8 ModelResourceLocation (net.minecraft.client.resources.model.ModelResourceLocation)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)7 Item (net.minecraft.item.Item)5 ResourceLocation (net.minecraft.util.ResourceLocation)5 IIEMetaBlock (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock)2 DimletType (mcjty.rftoolsdim.dimensions.dimlets.types.DimletType)2 Block (net.minecraft.block.Block)2 IColoredItem (biomesoplenty.common.item.IColoredItem)1 BlockIEFluid (blusunrize.immersiveengineering.common.blocks.BlockIEFluid)1 IColouredBlock (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IColouredBlock)1 IColouredItem (blusunrize.immersiveengineering.common.items.IEItemInterfaces.IColouredItem)1 IGuiItem (blusunrize.immersiveengineering.common.items.IEItemInterfaces.IGuiItem)1 IECompatModule (blusunrize.immersiveengineering.common.util.compat.IECompatModule)1 PositionedItemStack (blusunrize.lib.manual.ManualPages.PositionedItemStack)1 CookedItem (com.skelril.nitro.registry.item.CookedItem)1 ICustomItem (com.skelril.nitro.registry.item.ICustomItem)1 BlockITFluid (ferro2000.immersivetech.common.blocks.BlockITFluid)1