Search in sources :

Example 1 with IIEMetaBlock

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock 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 2 with IIEMetaBlock

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock in project ImmersiveEngineering by BluSunrize.

the class IECustomStateMapper method getModelResourceLocation.

@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
    try {
        ResourceLocation rl = Block.REGISTRY.getNameForObject(state.getBlock());
        IIEMetaBlock metaBlock = (IIEMetaBlock) state.getBlock();
        String custom = metaBlock.getCustomStateMapping(state.getBlock().getMetaFromState(state), false);
        if (custom != null)
            rl = new ResourceLocation(rl.toString() + "_" + custom);
        String prop = metaBlock.appendPropertiesToState() ? this.getPropertyString(state.getProperties()) : null;
        return new ModelResourceLocation(rl, prop);
    } catch (Exception e) {
        e.printStackTrace();
        ResourceLocation rl = Block.REGISTRY.getNameForObject(state.getBlock());
        return new ModelResourceLocation(rl, this.getPropertyString(state.getProperties()));
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IIEMetaBlock(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Aggregations

IIEMetaBlock (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IIEMetaBlock)2 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 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 IOException (java.io.IOException)1 Block (net.minecraft.block.Block)1 ItemMeshDefinition (net.minecraft.client.renderer.ItemMeshDefinition)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1