Advertisement
Guest User

Leaves

a guest
Feb 25th, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. public class BlockCherryLeaves extends Block implements IShearable {
  2. int[] surroundings;
  3.  
  4. public BlockCherryLeaves(String name) {
  5. super(Material.LEAVES);
  6. setTickRandomly(true);
  7. setHardness(0.2F);
  8. setLightOpacity(1);
  9. setUnlocalizedName(name);
  10. setRegistryName(name);
  11. setCreativeTab(Main.MAIN_TAB);
  12. setSoundType(SoundType.PLANT);
  13.  
  14. BlockInit.BLOCKS.add(this);
  15. ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
  16. }
  17.  
  18. @SuppressWarnings("deprecation")
  19. @SideOnly(Side.CLIENT)
  20. public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
  21. if (worldIn.isRainingAt(pos.up()) && !worldIn.getBlockState(pos.down()).isTopSolid() && rand.nextInt(15) == 1) {
  22. double d0 = (double) ((float) pos.getX() + rand.nextFloat());
  23. double d1 = (double) pos.getY() - 0.05D;
  24. double d2 = (double) ((float) pos.getZ() + rand.nextFloat());
  25. worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D);
  26. }
  27. }
  28.  
  29. public int quantityDropped(Random random) {
  30. return random.nextInt(20) == 0 ? 1 : 0;
  31. }
  32.  
  33. public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  34. return Item.getItemFromBlock(Blocks.SAPLING);
  35. }
  36.  
  37. public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) {
  38. super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
  39. }
  40.  
  41. protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance) {
  42. }
  43.  
  44. protected int getSaplingDropChance(IBlockState state) {
  45. return 20;
  46. }
  47.  
  48. public boolean isOpaqueCube(IBlockState state) {
  49. return false;
  50. }
  51.  
  52. @SideOnly(Side.CLIENT)
  53. public BlockRenderLayer getBlockLayer() {
  54. return BlockRenderLayer.CUTOUT_MIPPED;
  55. }
  56.  
  57. public boolean causesSuffocation(IBlockState state) {
  58. return false;
  59. }
  60.  
  61. @Override
  62. public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos) {
  63. return true;
  64. }
  65.  
  66. @Override
  67. public boolean isLeaves(IBlockState state, IBlockAccess world, BlockPos pos) {
  68. return true;
  69. }
  70.  
  71. @Override
  72. public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos,
  73. IBlockState state, int fortune) {
  74. Random rand = world instanceof World ? ((World) world).rand : new Random();
  75. int chance = this.getSaplingDropChance(state);
  76.  
  77. if (fortune > 0) {
  78. chance -= 2 << fortune;
  79. if (chance < 10)
  80. chance = 10;
  81. }
  82.  
  83. if (rand.nextInt(chance) == 0) {
  84. ItemStack drop = new ItemStack(getItemDropped(state, rand, fortune), 1, damageDropped(state));
  85. if (!drop.isEmpty())
  86. drops.add(drop);
  87. }
  88.  
  89. chance = 200;
  90. if (fortune > 0) {
  91. chance -= 10 << fortune;
  92. if (chance < 40)
  93. chance = 40;
  94. }
  95.  
  96. this.captureDrops(true);
  97. if (world instanceof World)
  98. this.dropApple((World) world, pos, state, chance); // Dammet mojang
  99. drops.addAll(this.captureDrops(false));
  100. }
  101.  
  102. @Override
  103. public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
  104. return NonNullList.withSize(1, new ItemStack(this));
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement