Search in sources :

Example 1 with IBOPBlock

use of biomesoplenty.common.block.IBOPBlock in project BiomesOPlenty by Glitchfiend.

the class ModBlocks method registerBlock.

public static Block registerBlock(Block block, String blockName, CreativeTabs tab, boolean registerItemModels) {
    Preconditions.checkNotNull(block, "Cannot register a null block");
    block.setUnlocalizedName(blockName);
    block.setCreativeTab(tab);
    if (block instanceof IBOPBlock) {
        // if this block supports the IBOPBlock interface then we can determine the item block class, and sub-blocks automatically
        IBOPBlock bopBlock = (IBOPBlock) block;
        registerBlockWithItem(block, blockName, bopBlock.getItemClass());
        BiomesOPlenty.proxy.registerBlockSided(block);
        // check for missing default states
        IBlockState defaultState = block.getDefaultState();
        if (defaultState == null) {
            defaultState = block.getBlockState().getBaseState();
            BiomesOPlenty.logger.error("Missing default state for " + block.getUnlocalizedName());
        }
        // Some blocks such as doors and slabs register their items after the blocks (getItemClass returns null)
        if (registerItemModels) {
            // get the preset blocks variants
            ImmutableSet<IBlockState> presets = BlockStateUtils.getBlockPresets(block);
            if (presets.isEmpty()) {
                // block has no sub-blocks to register
                registerBlockItemModel(block, blockName, 0);
            } else {
                // register all the sub-blocks
                for (IBlockState state : presets) {
                    String stateName = bopBlock.getStateName(state);
                    int stateMeta = block.getMetaFromState(state);
                    registerBlockItemModel(block, stateName, stateMeta);
                }
            }
        }
    } else {
        // for vanilla blocks, just register a single variant with meta=0 and assume ItemBlock for the item class
        registerBlockWithItem(block, blockName, ItemBlock.class);
        registerBlockItemModel(block, blockName, 0);
    }
    return block;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBOPBlock(biomesoplenty.common.block.IBOPBlock)

Example 2 with IBOPBlock

use of biomesoplenty.common.block.IBOPBlock in project BiomesOPlenty by Glitchfiend.

the class SilkTouchEventHandler method onSilkTouched.

@SubscribeEvent
public void onSilkTouched(BlockEvent.HarvestDropsEvent event) {
    IBlockState state = event.getState();
    if (state.getBlock() instanceof IBOPBlock && event.isSilkTouching()) {
        event.getDrops().clear();
        event.getDrops().add(state.getBlock().getPickBlock(state, null, event.getWorld(), event.getPos(), event.getHarvester()));
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBOPBlock(biomesoplenty.common.block.IBOPBlock) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IBOPBlock

use of biomesoplenty.common.block.IBOPBlock in project BiomesOPlenty by Glitchfiend.

the class ClientProxy method registerColouring.

@Override
public void registerColouring() {
    // do this here purely for timing reasons
    ModelLoader.registerItemVariants(ForgeModContainer.getInstance().universalBucket, bucketModelLocations);
    for (Block block : blocksToColour) {
        IBOPBlock bopBlock = (IBOPBlock) block;
        if (bopBlock.getBlockColor() != null)
            Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(bopBlock.getBlockColor(), block);
        if (bopBlock.getItemColor() != null)
            Minecraft.getMinecraft().getItemColors().registerItemColorHandler(bopBlock.getItemColor(), block);
    }
    for (Item item : itemsToColor) {
        IColoredItem coloredItem = (IColoredItem) item;
        Minecraft.getMinecraft().getItemColors().registerItemColorHandler(coloredItem.getItemColor(), item);
    }
}
Also used : Item(net.minecraft.item.Item) IColoredItem(biomesoplenty.common.item.IColoredItem) IBOPBlock(biomesoplenty.common.block.IBOPBlock) Block(net.minecraft.block.Block) IBOPBlock(biomesoplenty.common.block.IBOPBlock) IColoredItem(biomesoplenty.common.item.IColoredItem)

Example 4 with IBOPBlock

use of biomesoplenty.common.block.IBOPBlock in project BiomesOPlenty by Glitchfiend.

the class ClientProxy method registerBlockSided.

@Override
public void registerBlockSided(Block block) {
    if (block instanceof IBOPBlock) {
        IBOPBlock bopBlock = (IBOPBlock) block;
        // Register non-rendering properties
        IProperty[] nonRenderingProperties = bopBlock.getNonRenderingProperties();
        if (nonRenderingProperties != null) {
            // use a custom state mapper which will ignore the properties specified in the block as being non-rendering
            IStateMapper custom_mapper = (new StateMap.Builder()).ignore(nonRenderingProperties).build();
            ModelLoader.setCustomStateMapper(block, custom_mapper);
        }
        // Register colour handlers
        if (bopBlock.getBlockColor() != null || bopBlock.getItemColor() != null) {
            blocksToColour.add(block);
        }
    }
}
Also used : IBOPBlock(biomesoplenty.common.block.IBOPBlock) IProperty(net.minecraft.block.properties.IProperty) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) IStateMapper(net.minecraft.client.renderer.block.statemap.IStateMapper)

Aggregations

IBOPBlock (biomesoplenty.common.block.IBOPBlock)4 IBlockState (net.minecraft.block.state.IBlockState)2 IColoredItem (biomesoplenty.common.item.IColoredItem)1 Block (net.minecraft.block.Block)1 IProperty (net.minecraft.block.properties.IProperty)1 IStateMapper (net.minecraft.client.renderer.block.statemap.IStateMapper)1 StateMap (net.minecraft.client.renderer.block.statemap.StateMap)1 Item (net.minecraft.item.Item)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1