Search in sources :

Example 1 with DefaultStateMapper

use of net.minecraft.client.renderer.block.statemap.DefaultStateMapper in project Railcraft by Railcraft.

the class IRailcraftItemBlock method getModelLocation.

@SideOnly(Side.CLIENT)
default default ModelResourceLocation getModelLocation(IBlockState state) {
    StateMapperBase stateMapper = null;
    if (state.getBlock() instanceof IRailcraftBlock)
        stateMapper = ((IRailcraftBlock) state.getBlock()).getStateMapper();
    if (stateMapper == null)
        return new ModelResourceLocation(state.getBlock().getRegistryName(), new DefaultStateMapper().getPropertyString(state.getProperties()));
    Map<IBlockState, ModelResourceLocation> stateMap = stateMapper.putStateModelLocations(state.getBlock());
    return stateMap.get(state);
}
Also used : StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with DefaultStateMapper

use of net.minecraft.client.renderer.block.statemap.DefaultStateMapper 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 3 with DefaultStateMapper

use of net.minecraft.client.renderer.block.statemap.DefaultStateMapper in project EnderIO by SleepyTrousers.

the class BlockDecoration method registerRenderers.

@Override
@SideOnly(Side.CLIENT)
public void registerRenderers(@Nonnull IModObject modObject) {
    Item item = Item.getItemFromBlock(this);
    Map<IBlockState, ModelResourceLocation> locations = new DefaultStateMapper().putStateModelLocations(this);
    NNIterator<EnumDecoBlock> iterator = NNList.of(EnumDecoBlock.class).iterator();
    while (iterator.hasNext()) {
        EnumDecoBlock type = iterator.next();
        IBlockState state = getDefaultState().withProperty(EnumDecoBlock.TYPE, type);
        ModelResourceLocation mrl = locations.get(state);
        if (mrl != null) {
            ModelLoader.setCustomModelResourceLocation(item, EnumDecoBlock.getMetaFromType(type), mrl);
        }
    }
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) EnumDecoBlock(crazypants.enderio.base.render.property.EnumDecoBlock) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with DefaultStateMapper

use of net.minecraft.client.renderer.block.statemap.DefaultStateMapper in project EnderIO by SleepyTrousers.

the class BlockDecorationFacing method registerRenderers.

@Override
@SideOnly(Side.CLIENT)
public void registerRenderers(@Nonnull IModObject modObject) {
    Item item = Item.getItemFromBlock(this);
    Map<IBlockState, ModelResourceLocation> locations = new DefaultStateMapper().putStateModelLocations(this);
    NNIterator<EnumDecoBlock> iterator = NNList.of(EnumDecoBlock.class).iterator();
    while (iterator.hasNext()) {
        EnumDecoBlock type = iterator.next();
        IBlockState state = getDefaultState().withProperty(EnumDecoBlock.TYPE, type).withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVE, false);
        ModelResourceLocation mrl = locations.get(state);
        if (mrl != null) {
            ModelLoader.setCustomModelResourceLocation(item, EnumDecoBlock.getMetaFromType(type), mrl);
        }
    }
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) EnumDecoBlock(crazypants.enderio.base.render.property.EnumDecoBlock) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with DefaultStateMapper

use of net.minecraft.client.renderer.block.statemap.DefaultStateMapper in project RebornCore by TechReborn.

the class ModelMethods method setBlockStateMapper.

public static void setBlockStateMapper(Block block, String fileName, String path, IProperty... ignoredProperties) {
    final String slash = !path.isEmpty() ? "/" : "";
    ModelLoader.setCustomStateMapper(block, new DefaultStateMapper() {

        @Override
        protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
            Map<IProperty<?>, Comparable<?>> map = Maps.<IProperty<?>, Comparable<?>>newLinkedHashMap(state.getProperties());
            for (IProperty<?> iproperty : ignoredProperties) {
                map.remove(iproperty);
            }
            return new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), path + slash + fileName), this.getPropertyString(map));
        }
    });
}
Also used : DefaultStateMapper(net.minecraft.client.renderer.block.statemap.DefaultStateMapper) IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Map(java.util.Map)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)8 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)8 DefaultStateMapper (net.minecraft.client.renderer.block.statemap.DefaultStateMapper)8 Item (net.minecraft.item.Item)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 Map (java.util.Map)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 EnumDecoBlock (crazypants.enderio.base.render.property.EnumDecoBlock)2 IProperty (net.minecraft.block.properties.IProperty)2 EnumType (com.codetaylor.mc.artisanworktables.api.internal.reference.EnumType)1 Nonnull (javax.annotation.Nonnull)1 Block (net.minecraft.block.Block)1 StateMapperBase (net.minecraft.client.renderer.block.statemap.StateMapperBase)1 EnumCableType (techreborn.blocks.cable.EnumCableType)1