Advertisement
Guest User

Example

a guest
Oct 3rd, 2019
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.15 KB | None | 0 0
  1. // Your plant code should look something like this
  2.  
  3. public static class BlockCustomFlower extends BlockFlower {
  4.         public BlockCustomFlower() {
  5.             setSoundType(SoundType.PLANT);
  6.             setCreativeTab(CreativeTabs.DECORATIONS);
  7.             setHardness(0F);
  8.             setResistance(0F);
  9.             setLightLevel(0F);
  10.             setUnlocalizedName("ocotillo");
  11.             setRegistryName("ocotillo");
  12.         }
  13.  
  14.         @Override
  15.         public BlockFlower.EnumFlowerColor getBlockType() {
  16.             return BlockFlower.EnumFlowerColor.YELLOW;
  17.         }
  18.  
  19.         @SideOnly(Side.CLIENT)
  20.         @Override
  21.         public void getSubBlocks(CreativeTabs tab, net.minecraft.util.NonNullList<ItemStack> list) {
  22.             for (BlockFlower.EnumFlowerType blockflower$enumflowertype : BlockFlower.EnumFlowerType.getTypes(this.getBlockType())) {
  23.                 list.add(new ItemStack(this, 1, blockflower$enumflowertype.getMeta()));
  24.             }
  25.         }
  26.         // Up to here it's just the default MCreator code
  27.  
  28.         // This plant grows on sand, (stained) terracotta and dirt
  29.         // You need canSustainBush, canPlaceBlockAt and canBlockStay to make it work properly
  30.         // Don't worry about imports, just press ctrl+w after pasting the stuff from here...
  31.         @Override
  32.         protected boolean canSustainBush(IBlockState state) {
  33.             return state.getBlock() == Blocks.SAND || state.getBlock() == Blocks.HARDENED_CLAY || state.getBlock() == Blocks.DIRT
  34.                     || state.getBlock() == Blocks.STAINED_HARDENED_CLAY;
  35.         }
  36.  
  37.         @Override
  38.         public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
  39.             IBlockState soil = worldIn.getBlockState(pos.down());
  40.             Block block = soil.getBlock();
  41.             return block == Blocks.SAND || block == Blocks.HARDENED_CLAY || block == Blocks.DIRT || block == Blocks.STAINED_HARDENED_CLAY;
  42.         }
  43.  
  44.         @Override
  45.         public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
  46.             if (pos.getY() >= 0 && pos.getY() < 256) {
  47.                 IBlockState iblockstate = worldIn.getBlockState(pos.down());
  48.                 Block block = iblockstate.getBlock();
  49.                 return block == Blocks.SAND || block == Blocks.HARDENED_CLAY || block == Blocks.DIRT || block == Blocks.STAINED_HARDENED_CLAY;
  50.             } else
  51.                 return false;
  52.         }
  53.         // ...to here
  54.     }
  55. }
  56.  
  57. // Say you want to make the plant grow on a block you created (for example a ruby block)
  58. // You need to know the name of your block element (the one you pick when you created the block)
  59. // Let's say the name of the ruby block is RubyBlock
  60. // In this example, the plant grows on the custom ruby block instead
  61. public static class BlockCustomFlower extends BlockFlower {
  62.         public BlockCustomFlower() {
  63.             setSoundType(SoundType.PLANT);
  64.             setCreativeTab(CreativeTabs.DECORATIONS);
  65.             setHardness(0F);
  66.             setResistance(0F);
  67.             setLightLevel(0F);
  68.             setUnlocalizedName("ocotillo");
  69.             setRegistryName("ocotillo");
  70.         }
  71.  
  72.         @Override
  73.         public BlockFlower.EnumFlowerColor getBlockType() {
  74.             return BlockFlower.EnumFlowerColor.YELLOW;
  75.         }
  76.  
  77.         @SideOnly(Side.CLIENT)
  78.         @Override
  79.         public void getSubBlocks(CreativeTabs tab, net.minecraft.util.NonNullList<ItemStack> list) {
  80.             for (BlockFlower.EnumFlowerType blockflower$enumflowertype : BlockFlower.EnumFlowerType.getTypes(this.getBlockType())) {
  81.                 list.add(new ItemStack(this, 1, blockflower$enumflowertype.getMeta()));
  82.             }
  83.         }
  84.  
  85.         // This plant grows on ruby blocks
  86.         // I replaced the Blocks.SAND, Blocks.DIRT etc. with MCreatorRubyBlock.block
  87.         // In general, for any block element called "BlockElement", you can get the block with "MCreatorBlockElement.block"
  88.         // Again, don't forget to press ctrl+w after copying this stuff!
  89.         @Override
  90.         protected boolean canSustainBush(IBlockState state) {
  91.             return state.getBlock() == MCreatorRubyBlock.block;
  92.         }
  93.  
  94.         @Override
  95.         public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
  96.             IBlockState soil = worldIn.getBlockState(pos.down());
  97.             Block block = soil.getBlock();
  98.             return block == MCreatorRubyBlock.block;
  99.         }
  100.  
  101.         @Override
  102.         public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
  103.             if (pos.getY() >= 0 && pos.getY() < 256) {
  104.                 IBlockState iblockstate = worldIn.getBlockState(pos.down());
  105.                 Block block = iblockstate.getBlock();
  106.                 return block == MCreatorRubyBlock.block;
  107.             } else
  108.                 return false;
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement