Search in sources :

Example 46 with IProperty

use of net.minecraft.block.properties.IProperty in project Tropicraft by Tropicraft.

the class WorldGenHomeTree method genVines.

public void genVines(int i, int j, int k) {
    int length = rand.nextInt(15) + 8;
    int dir = rand.nextInt(4);
    IProperty direction = null;
    if (dir == 0)
        direction = BlockVine.NORTH;
    if (dir == 1)
        direction = BlockVine.SOUTH;
    if (dir == 2)
        direction = BlockVine.EAST;
    if (dir == 3)
        direction = BlockVine.WEST;
    for (int y = j; y > j - length; y--) {
        if (TCGenUtils.isAirBlock(worldObj, i, y, k)) {
            placeBlock(i, y, k, Blocks.VINE.getDefaultState().withProperty(direction, Boolean.valueOf(true)), false);
        } else
            break;
    }
}
Also used : IProperty(net.minecraft.block.properties.IProperty)

Example 47 with IProperty

use of net.minecraft.block.properties.IProperty in project EnderIO by SleepyTrousers.

the class ClientProxy method onModelRegistryEvent.

@SubscribeEvent
public static void onModelRegistryEvent(@Nonnull ModelRegistryEvent event) {
    // Custom state mappers
    EnderIOGlassesStateMapper.create();
    ColdFireStateMapper.create();
    LeverStateMapper.create();
    final StateMap doorMapper = (new StateMap.Builder()).ignore(new IProperty[] { BlockDoor.POWERED }).build();
    ModelLoader.setCustomStateMapper(ModObject.blockDarkSteelDoor.getBlockNN(), doorMapper);
    ModelLoader.setCustomStateMapper(ModObject.blockPaintedDarkSteelDoor.getBlockNN(), doorMapper);
    ModelLoader.setCustomStateMapper(ModObject.blockPaintedIronDoor.getBlockNN(), doorMapper);
    ModelLoader.setCustomStateMapper(ModObject.blockPaintedWoodenDoor.getBlockNN(), doorMapper);
    // Items of blocks that use smart rendering
    SmartModelAttacher.registerBlockItemModels();
    /*
     * Most blocks register themselves with the SmartModelAttacher which will also handle their items. Those that don't need to implement IHaveRenderers and
     * have their items handled here.
     * 
     * Items that do _not_ belong to a block are handled here by either having the item implement IHaveRenderers or by registering the default renderer.
     */
    for (IModObject mo : ModObjectRegistry.getObjects()) {
        final Block block = mo.getBlock();
        if (block instanceof ICustomSubItems) {
        // NOP, handled by SmartModelAttacher
        } else if (block instanceof IHaveRenderers) {
            ((IHaveRenderers) block).registerRenderers(mo);
        } else if (block instanceof IDefaultRenderers) {
            ClientUtil.registerDefaultItemRenderer(mo);
        } else if (block == null || block == Blocks.AIR) {
            final Item item = mo.getItem();
            if (item instanceof ICustomSubItems) {
            // NOP, handled by SmartModelAttacher
            } else if (item instanceof IHaveRenderers) {
                ((IHaveRenderers) item).registerRenderers(mo);
            } else if (item != null && item != Items.AIR) {
                ClientUtil.registerDefaultItemRenderer(mo);
            }
        }
        if (block instanceof IHaveTESR) {
            ((IHaveTESR) block).bindTileEntitySpecialRenderer();
        }
    }
}
Also used : Item(net.minecraft.item.Item) ICustomSubItems(crazypants.enderio.base.render.ICustomSubItems) IProperty(net.minecraft.block.properties.IProperty) IHaveTESR(crazypants.enderio.base.render.IHaveTESR) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) IDefaultRenderers(crazypants.enderio.base.render.IDefaultRenderers) Block(net.minecraft.block.Block) IHaveRenderers(crazypants.enderio.base.render.IHaveRenderers) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 48 with IProperty

use of net.minecraft.block.properties.IProperty in project EnderIO by SleepyTrousers.

the class SmartModelAttacher method bakeModels.

@SuppressWarnings({ "rawtypes", "unchecked" })
@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void bakeModels(@Nonnull ModelBakeEvent event) {
    for (RegistrationHolder holder : blocks) {
        Block block = holder.block;
        Map<IBlockState, ModelResourceLocation> locations = event.getModelManager().getBlockModelShapes().getBlockStateMapper().getVariants(block);
        final IProperty holder_property = holder.property;
        final Comparable holder_defaultsValue = holder.defaultsValue;
        final IBakedModel missingModel = event.getModelManager().getMissingModel();
        if (holder_property != null && block.getDefaultState().getPropertyKeys().contains(holder_property) && holder_defaultsValue != null) {
            IBlockState defaultState = block.getDefaultState().withProperty(holder_property, holder_defaultsValue);
            ModelResourceLocation defaultMrl = locations.get(defaultState);
            if (defaultMrl == null) {
                throw new RuntimeException("Model for state " + defaultState + " failed to load from " + defaultMrl + ". " + debugOutput(event.getModelRegistry(), defaultMrl, missingModel));
            }
            IBakedModel defaultBakedModel = event.getModelRegistry().getObject(defaultMrl);
            if (defaultBakedModel == null) {
                Log.warn("ModelBakeEvent: cannot register smart model over null model for " + holder.block + ". See model errors below.");
                continue;
            }
            RelayingBakedModel model = new RelayingBakedModel(defaultBakedModel);
            ModelResourceLocation itemMrl = new ModelResourceLocation(defaultMrl.getResourceDomain() + ":" + defaultMrl.getResourcePath() + "#inventory");
            event.getModelRegistry().putObject(itemMrl, model);
            if (defaultBakedModel == missingModel) {
                // This is normal on the first pass. We register our synthetic models above anyway to avoid model loading errors.
                continue;
            }
            for (Entry<IBlockState, ModelResourceLocation> entry : locations.entrySet()) {
                final ModelResourceLocation entryMrl = NullHelper.notnullF(entry.getValue(), "BlockModelShapes contains null keys");
                final IBlockState entryBlockstate = entry.getKey();
                final IBakedModel existingModel = event.getModelRegistry().getObject(entryMrl);
                if (existingModel == null || existingModel == missingModel) {
                    event.getModelRegistry().putObject(entryMrl, defaultBakedModel);
                } else if (entryBlockstate.getValue(holder_property) == holder.autoValue) {
                    event.getModelRegistry().putObject(entryMrl, model);
                }
            }
        } else {
            IBlockState defaultState = block.getDefaultState();
            ModelResourceLocation defaultMrl = locations.get(defaultState);
            if (defaultMrl == null) {
                throw new RuntimeException("Model for state " + defaultState + " failed to load from " + defaultMrl + ". " + debugOutput(event.getModelRegistry(), defaultMrl, missingModel));
            }
            IBakedModel defaultBakedModel = event.getModelRegistry().getObject(defaultMrl);
            if (defaultBakedModel == null || defaultBakedModel == missingModel) {
                continue;
            }
            if (!holder.itemOnly) {
                for (ModelResourceLocation mrl0 : locations.values()) {
                    final ModelResourceLocation mrl = NullHelper.notnullF(mrl0, "BlockModelShapes contains null keys");
                    IBakedModel model = event.getModelRegistry().getObject(mrl);
                    if (model == null || model == missingModel) {
                    } else {
                        event.getModelRegistry().putObject(mrl, new RelayingBakedModel(NullHelper.first(model, defaultBakedModel)));
                    }
                }
            }
            ModelResourceLocation itemMrl = new ModelResourceLocation(defaultMrl.getResourceDomain() + ":" + defaultMrl.getResourcePath() + "#inventory");
            final IBakedModel model = event.getModelRegistry().getObject(itemMrl);
            if (model == null || model == missingModel) {
                event.getModelRegistry().putObject(itemMrl, new RelayingBakedModel(defaultBakedModel));
            } else {
                event.getModelRegistry().putObject(itemMrl, new RelayingBakedModel(model));
            }
        }
    }
    OverlayHolder.collectOverlayQuads(event);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RelayingBakedModel(crazypants.enderio.base.render.model.RelayingBakedModel) IProperty(net.minecraft.block.properties.IProperty) ITintedBlock(crazypants.enderio.base.render.ITintedBlock) Block(net.minecraft.block.Block) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 49 with IProperty

use of net.minecraft.block.properties.IProperty in project ForestryMC by ForestryMC.

the class CropRubber method getReplantState.

/**
 * Convert a "wet" rubber log blockstate into the dry version.
 * Total hack since we don't have access to the blockstates.
 */
private static <T extends Comparable<T>> IBlockState getReplantState(IBlockState sappyState) {
    if (hasRubberToHarvest(sappyState)) {
        for (Map.Entry<IProperty<?>, Comparable<?>> wetPropertyEntry : sappyState.getProperties().entrySet()) {
            String valueWetString = wetPropertyEntry.getValue().toString();
            String valueDryString = valueWetString.replace("wet", "dry");
            IProperty<?> property = wetPropertyEntry.getKey();
            IBlockState baseState = sappyState.getBlock().getBlockState().getBaseState();
            IBlockState dryState = getStateWithValue(baseState, property, valueDryString);
            if (dryState != null) {
                return dryState;
            }
        }
    }
    return sappyState.getBlock().getDefaultState();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) Map(java.util.Map)

Example 50 with IProperty

use of net.minecraft.block.properties.IProperty in project ForestryMC by ForestryMC.

the class WoodTypeStateMapper method getDefaultModelResourceLocation.

@Override
public ModelResourceLocation getDefaultModelResourceLocation(IBlockState state) {
    final Map<IProperty<?>, Comparable<?>> properties;
    if (propertyWoodType != null) {
        properties = Maps.newLinkedHashMap(state.getProperties());
        properties.remove(propertyWoodType);
    } else {
        properties = Maps.newLinkedHashMap(state.getProperties());
    }
    for (IProperty property : propertiesToRemove) {
        properties.remove(property);
    }
    String resourceLocation = "arboriculture/" + blockPath;
    String propertyString = this.getPropertyString(properties);
    return new ModelResourceLocation(Constants.MOD_ID + ':' + resourceLocation, propertyString);
}
Also used : IProperty(net.minecraft.block.properties.IProperty) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Aggregations

IProperty (net.minecraft.block.properties.IProperty)72 IBlockState (net.minecraft.block.state.IBlockState)39 Block (net.minecraft.block.Block)20 ResourceLocation (net.minecraft.util.ResourceLocation)14 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)11 ItemStack (net.minecraft.item.ItemStack)10 EnumFacing (net.minecraft.util.EnumFacing)10 Map (java.util.Map)9 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)9 ArrayList (java.util.ArrayList)8 BlockStateContainer (net.minecraft.block.state.BlockStateContainer)8 TileEntity (net.minecraft.tileentity.TileEntity)7 BlockPos (net.minecraft.util.math.BlockPos)7 JsonObject (com.google.gson.JsonObject)6 DrawBlock (com.microsoft.Malmo.Schemas.DrawBlock)5 ExtendedBlockState (net.minecraftforge.common.property.ExtendedBlockState)5 JsonArray (com.google.gson.JsonArray)4 JsonElement (com.google.gson.JsonElement)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4