Search in sources :

Example 66 with ModelResourceLocation

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

the class RegistrationHelper method registerRender.

/**
 * @param item
 */
@SideOnly(Side.CLIENT)
public static void registerRender(@Nonnull final Item item) {
    final ResourceLocation resourceLocation = item.getRegistryName();
    if (!resourceLocation.getResourceDomain().equals(Loader.instance().activeModContainer().getModId())) {
        return;
    }
    ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(resourceLocation, "inventory"));
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 67 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project artisan-worktables by codetaylor.

the class ModuleTools method onClientRegister.

@Override
public void onClientRegister(Registry registry) {
    super.onClientRegister(registry);
    registry.registerClientModelRegistrationStrategy(() -> {
        for (ItemWorktableTool item : ModuleTools.this.registeredToolList) {
            String resourcePath = item.getMaterial().getDataCustomMaterial().isShiny() ? item.getName() + "_highlighted" : item.getName();
            ResourceLocation location = new ResourceLocation(MOD_ID, resourcePath);
            ModelResourceLocation modelResourceLocation = new ModelResourceLocation(location, "inventory");
            ModelLoader.setCustomModelResourceLocation(item, 0, modelResourceLocation);
        }
    });
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemWorktableTool(com.codetaylor.mc.artisanworktables.modules.tools.item.ItemWorktableTool) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 68 with ModelResourceLocation

use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project artisan-worktables by codetaylor.

the class BlockModelRegistrationStrategy method register.

@Override
public void register() {
    BlockBase.VARIANT.getAllowedValues().forEach(type -> {
        IBlockState state = this.block.getDefaultState().withProperty(BlockBase.VARIANT, type);
        Block block = state.getBlock();
        Item item = Item.getItemFromBlock(block);
        ModelLoader.setCustomModelResourceLocation(item, type.getMeta(), new ModelResourceLocation(Preconditions.checkNotNull(item.getRegistryName(), "Item %s has null registry name", item), BlockBase.VARIANT.getName() + "=" + type.getName()));
    });
    IBlockState state = this.block.getDefaultState().withProperty(BlockBase.VARIANT, EnumType.MAGE);
    Block block = state.getBlock();
    Item item = Item.getItemFromBlock(block);
    ModelLoader.setCustomModelResourceLocation(item, Short.MAX_VALUE / 2 + EnumType.MAGE.getMeta(), new ModelResourceLocation(Preconditions.checkNotNull(item.getRegistryName(), "Item %s has null registry name", item), BlockBase.VARIANT.getName() + "=" + EnumType.MAGE.getName() + "_active"));
    ModelLoader.setCustomStateMapper(this.block, new DefaultStateMapper() {

        @Nonnull
        @Override
        protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
            EnumType type = state.getValue(BlockBase.VARIANT);
            if (type == EnumType.MAGE) {
                Block block = state.getBlock();
                boolean active = state.getValue(BlockBase.ACTIVE);
                return new ModelResourceLocation(Preconditions.checkNotNull(Block.REGISTRY.getNameForObject(block), "Block %s has null registry name", block), BlockBase.VARIANT.getName() + "=" + type.getName() + (active ? "_active" : ""));
            } else {
                Block block = state.getBlock();
                return new ModelResourceLocation(Preconditions.checkNotNull(Block.REGISTRY.getNameForObject(block), "Block %s has null registry name", block), BlockBase.VARIANT.getName() + "=" + type.getName());
            }
        }
    });
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) Nonnull(javax.annotation.Nonnull) EnumType(com.codetaylor.mc.artisanworktables.api.internal.reference.EnumType) Block(net.minecraft.block.Block) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 69 with ModelResourceLocation

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

the class ProxyArboricultureClient method onModelBake.

@SubscribeEvent
public <T extends Block & IWoodTyped> void onModelBake(ModelBakeEvent event) {
    IRegistry<ModelResourceLocation, IBakedModel> registry = event.getModelRegistry();
    for (WoodModelEntry<T> entry : woodModelEntrys) {
        T woodTyped = entry.woodTyped;
        WoodBlockKind woodKind = woodTyped.getBlockKind();
        IWoodStateMapper woodMapper = stateMappers.get(woodTyped);
        for (IBlockState blockState : woodTyped.getBlockState().getValidStates()) {
            IWoodType woodType;
            ItemStack itemStack;
            if (entry.withVariants) {
                int meta = woodTyped.getMetaFromState(blockState);
                woodType = woodTyped.getWoodType(meta);
                itemStack = new ItemStack(woodTyped, 1, meta);
            } else {
                woodType = woodTyped.getWoodType(0);
                itemStack = new ItemStack(woodTyped);
            }
            IWoodItemMeshDefinition definition = shapers.get(itemStack.getItem());
            ImmutableMap<String, String> textures = WoodTextureManager.getTextures(woodType, woodKind);
            if (definition != null) {
                retextureItemModel(registry, textures, woodType, woodKind, itemStack, definition);
            }
            if (woodMapper != null) {
                retexturBlockModel(registry, textures, woodType, woodKind, blockState, woodMapper);
            }
        }
    }
}
Also used : IWoodType(forestry.api.arboriculture.IWoodType) WoodBlockKind(forestry.api.arboriculture.WoodBlockKind) IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IWoodStateMapper(forestry.api.arboriculture.IWoodStateMapper) IWoodItemMeshDefinition(forestry.api.arboriculture.IWoodItemMeshDefinition) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 70 with ModelResourceLocation

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

the class SaplingStateMapper method putStateModelLocations.

@Override
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block) {
    for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
        if (allele instanceof IAlleleTreeSpecies) {
            IAlleleTreeSpecies tree = (IAlleleTreeSpecies) allele;
            IBlockState state = block.getDefaultState().withProperty(BlockSapling.TREE, tree);
            LinkedHashMap<IProperty<?>, Comparable<?>> linkedhashmap = Maps.newLinkedHashMap(state.getProperties());
            String modID = tree.getModID();
            String s = String.format("%s:%s", modID, "germlings");
            mapStateModelLocations.put(state, new ModelResourceLocation(s, getPropertyString(linkedhashmap)));
        }
    }
    return mapStateModelLocations;
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Aggregations

ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)320 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)129 ResourceLocation (net.minecraft.util.ResourceLocation)101 Item (net.minecraft.item.Item)55 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)52 IBlockState (net.minecraft.block.state.IBlockState)48 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)26 ArrayList (java.util.ArrayList)25 Block (net.minecraft.block.Block)21 StateMapperBase (net.minecraft.client.renderer.block.statemap.StateMapperBase)20 ItemStack (net.minecraft.item.ItemStack)16 EnumFacing (net.minecraft.util.EnumFacing)13 Map (java.util.Map)12 ItemMeshDefinition (net.minecraft.client.renderer.ItemMeshDefinition)11 IModel (net.minecraftforge.client.model.IModel)11 Nonnull (javax.annotation.Nonnull)10 IProperty (net.minecraft.block.properties.IProperty)9 Side (net.minecraftforge.fml.relauncher.Side)9 DefaultStateMapper (net.minecraft.client.renderer.block.statemap.DefaultStateMapper)8 RenderItem (net.minecraft.client.renderer.RenderItem)7