Search in sources :

Example 6 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project MinecraftForge by MinecraftForge.

the class MultiLayerModel method process.

@Override
public MultiLayerModel process(ImmutableMap<String, String> customData) {
    ImmutableMap.Builder<Optional<BlockRenderLayer>, ModelResourceLocation> builder = ImmutableMap.builder();
    for (String key : customData.keySet()) {
        if ("base".equals(key)) {
            builder.put(Optional.<BlockRenderLayer>absent(), getLocation(customData.get(key)));
        }
        for (BlockRenderLayer layer : BlockRenderLayer.values()) {
            if (layer.toString().equals(key)) {
                builder.put(Optional.of(layer), getLocation(customData.get(key)));
            }
        }
    }
    ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models = builder.build();
    if (models.isEmpty())
        return INSTANCE;
    return new MultiLayerModel(models);
}
Also used : Optional(com.google.common.base.Optional) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project MinecraftForge by MinecraftForge.

the class ModelLoader method setupModelRegistry.

@Override
public IRegistry<ModelResourceLocation, IBakedModel> setupModelRegistry() {
    isLoading = true;
    loadBlocks();
    loadVariantItemModels();
    missingModel = ModelLoaderRegistry.getMissingModel();
    stateModels.put(MODEL_MISSING, missingModel);
    final Set<ResourceLocation> textures = Sets.newHashSet(ModelLoaderRegistry.getTextures());
    textures.remove(TextureMap.LOCATION_MISSING_TEXTURE);
    textures.addAll(LOCATIONS_BUILTIN_TEXTURES);
    textureMap.loadSprites(resourceManager, new ITextureMapPopulator() {

        public void registerSprites(TextureMap map) {
            for (ResourceLocation t : textures) {
                map.registerSprite(t);
            }
        }
    });
    IBakedModel missingBaked = missingModel.bake(missingModel.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE);
    Map<IModel, IBakedModel> bakedModels = Maps.newHashMap();
    HashMultimap<IModel, ModelResourceLocation> models = HashMultimap.create();
    Multimaps.invertFrom(Multimaps.forMap(stateModels), models);
    if (firstLoad) {
        firstLoad = false;
        for (ModelResourceLocation mrl : stateModels.keySet()) {
            bakedRegistry.putObject(mrl, missingBaked);
        }
        return bakedRegistry;
    }
    ProgressBar bakeBar = ProgressManager.push("ModelLoader: baking", models.keySet().size());
    for (IModel model : models.keySet()) {
        bakeBar.step("[" + Joiner.on(", ").join(models.get(model)) + "]");
        if (model == getMissingModel()) {
            bakedModels.put(model, missingBaked);
        } else {
            bakedModels.put(model, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE));
        }
    }
    ProgressManager.pop(bakeBar);
    for (Entry<ModelResourceLocation, IModel> e : stateModels.entrySet()) {
        bakedRegistry.putObject(e.getKey(), bakedModels.get(e.getValue()));
    }
    return bakedRegistry;
}
Also used : TextureMap(net.minecraft.client.renderer.texture.TextureMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ITextureMapPopulator(net.minecraft.client.renderer.texture.ITextureMapPopulator) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar)

Example 8 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation 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 9 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project ImmersiveEngineering by BluSunrize.

the class ImmersiveModelRegistry method registerCustomItemModel.

public void registerCustomItemModel(ItemStack stack, ItemModelReplacement replacement) {
    if (stack.getItem() instanceof ItemIEBase) {
        ResourceLocation loc;
        if (((ItemIEBase) stack.getItem()).getSubNames() != null && ((ItemIEBase) stack.getItem()).getSubNames().length > 0)
            loc = new ResourceLocation("immersiveengineering", ((ItemIEBase) stack.getItem()).itemName + "/" + ((ItemIEBase) stack.getItem()).getSubNames()[stack.getItemDamage()]);
        else
            loc = new ResourceLocation("immersiveengineering", ((ItemIEBase) stack.getItem()).itemName);
        itemModelReplacements.put(new ModelResourceLocation(loc, "inventory"), replacement);
    }
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemIEBase(blusunrize.immersiveengineering.common.items.ItemIEBase)

Example 10 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project RFToolsDimensions by McJty.

the class DimensionMonitorItem method initModel.

@Override
@SideOnly(Side.CLIENT)
public void initModel() {
    for (int i = 0; i <= 8; i++) {
        ResourceLocation registryName = getRegistryName();
        registryName = new ResourceLocation(registryName.getResourceDomain(), registryName.getResourcePath() + i);
        ModelBakery.registerItemVariants(this, new ModelResourceLocation(registryName, "inventory"));
    //            ModelBakery.addVariantName(this, getRegistryName() + i);
    }
    ModelLoader.setCustomMeshDefinition(this, new ItemMeshDefinition() {

        @Override
        public ModelResourceLocation getModelLocation(ItemStack stack) {
            WorldClient world = MinecraftTools.getWorld(Minecraft.getMinecraft());
            int id = world.provider.getDimension();
            DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
            int energyLevel = storage.getEnergyLevel(id);
            int level = (9 * energyLevel) / PowerConfiguration.MAX_DIMENSION_POWER;
            if (level < 0) {
                level = 0;
            } else if (level > 8) {
                level = 8;
            }
            ResourceLocation registryName = getRegistryName();
            registryName = new ResourceLocation(registryName.getResourceDomain(), registryName.getResourcePath() + (8 - level));
            return new ModelResourceLocation(registryName, "inventory");
        }
    });
}
Also used : ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) 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) WorldClient(net.minecraft.client.multiplayer.WorldClient) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)95 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)42 ResourceLocation (net.minecraft.util.ResourceLocation)28 Item (net.minecraft.item.Item)19 ArrayList (java.util.ArrayList)17 ItemMeshDefinition (net.minecraft.client.renderer.ItemMeshDefinition)15 ItemStack (net.minecraft.item.ItemStack)13 IBlockState (net.minecraft.block.state.IBlockState)10 Block (net.minecraft.block.Block)7 RenderItem (net.minecraft.client.renderer.RenderItem)7 StateMapperBase (net.minecraft.client.renderer.block.statemap.StateMapperBase)7 EnumFacing (net.minecraft.util.EnumFacing)6 Map (java.util.Map)5 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)4 StateMap (net.minecraft.client.renderer.block.statemap.StateMap)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 HashMap (java.util.HashMap)3 BlockFenceGate (net.minecraft.block.BlockFenceGate)3 BlockSlab (net.minecraft.block.BlockSlab)3 BlockWall (net.minecraft.block.BlockWall)3