Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Your plant code should look something like this
- public static class BlockCustomFlower extends BlockFlower {
- public BlockCustomFlower() {
- setSoundType(SoundType.PLANT);
- setCreativeTab(CreativeTabs.DECORATIONS);
- setHardness(0F);
- setResistance(0F);
- setLightLevel(0F);
- setUnlocalizedName("ocotillo");
- setRegistryName("ocotillo");
- }
- @Override
- public BlockFlower.EnumFlowerColor getBlockType() {
- return BlockFlower.EnumFlowerColor.YELLOW;
- }
- @SideOnly(Side.CLIENT)
- @Override
- public void getSubBlocks(CreativeTabs tab, net.minecraft.util.NonNullList<ItemStack> list) {
- for (BlockFlower.EnumFlowerType blockflower$enumflowertype : BlockFlower.EnumFlowerType.getTypes(this.getBlockType())) {
- list.add(new ItemStack(this, 1, blockflower$enumflowertype.getMeta()));
- }
- }
- // Up to here it's just the default MCreator code
- // This plant grows on sand, (stained) terracotta and dirt
- // You need canSustainBush, canPlaceBlockAt and canBlockStay to make it work properly
- // Don't worry about imports, just press ctrl+w after pasting the stuff from here...
- @Override
- protected boolean canSustainBush(IBlockState state) {
- return state.getBlock() == Blocks.SAND || state.getBlock() == Blocks.HARDENED_CLAY || state.getBlock() == Blocks.DIRT
- || state.getBlock() == Blocks.STAINED_HARDENED_CLAY;
- }
- @Override
- public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
- IBlockState soil = worldIn.getBlockState(pos.down());
- Block block = soil.getBlock();
- return block == Blocks.SAND || block == Blocks.HARDENED_CLAY || block == Blocks.DIRT || block == Blocks.STAINED_HARDENED_CLAY;
- }
- @Override
- public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
- if (pos.getY() >= 0 && pos.getY() < 256) {
- IBlockState iblockstate = worldIn.getBlockState(pos.down());
- Block block = iblockstate.getBlock();
- return block == Blocks.SAND || block == Blocks.HARDENED_CLAY || block == Blocks.DIRT || block == Blocks.STAINED_HARDENED_CLAY;
- } else
- return false;
- }
- // ...to here
- }
- }
- // Say you want to make the plant grow on a block you created (for example a ruby block)
- // You need to know the name of your block element (the one you pick when you created the block)
- // Let's say the name of the ruby block is RubyBlock
- // In this example, the plant grows on the custom ruby block instead
- public static class BlockCustomFlower extends BlockFlower {
- public BlockCustomFlower() {
- setSoundType(SoundType.PLANT);
- setCreativeTab(CreativeTabs.DECORATIONS);
- setHardness(0F);
- setResistance(0F);
- setLightLevel(0F);
- setUnlocalizedName("ocotillo");
- setRegistryName("ocotillo");
- }
- @Override
- public BlockFlower.EnumFlowerColor getBlockType() {
- return BlockFlower.EnumFlowerColor.YELLOW;
- }
- @SideOnly(Side.CLIENT)
- @Override
- public void getSubBlocks(CreativeTabs tab, net.minecraft.util.NonNullList<ItemStack> list) {
- for (BlockFlower.EnumFlowerType blockflower$enumflowertype : BlockFlower.EnumFlowerType.getTypes(this.getBlockType())) {
- list.add(new ItemStack(this, 1, blockflower$enumflowertype.getMeta()));
- }
- }
- // This plant grows on ruby blocks
- // I replaced the Blocks.SAND, Blocks.DIRT etc. with MCreatorRubyBlock.block
- // In general, for any block element called "BlockElement", you can get the block with "MCreatorBlockElement.block"
- // Again, don't forget to press ctrl+w after copying this stuff!
- @Override
- protected boolean canSustainBush(IBlockState state) {
- return state.getBlock() == MCreatorRubyBlock.block;
- }
- @Override
- public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
- IBlockState soil = worldIn.getBlockState(pos.down());
- Block block = soil.getBlock();
- return block == MCreatorRubyBlock.block;
- }
- @Override
- public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
- if (pos.getY() >= 0 && pos.getY() < 256) {
- IBlockState iblockstate = worldIn.getBlockState(pos.down());
- Block block = iblockstate.getBlock();
- return block == MCreatorRubyBlock.block;
- } else
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement