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;
}
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()));
}
}
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);
}
}
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);
}
}
}
Aggregations