Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. package net.minecraft.block;
  2.  
  3. import java.util.Random;
  4. import javax.annotation.Nullable;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.properties.IProperty;
  7. import net.minecraft.block.properties.PropertyBool;
  8. import net.minecraft.block.state.BlockStateContainer;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.creativetab.CreativeTabs;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.util.BlockRenderLayer;
  14. import net.minecraft.util.math.BlockPos;
  15. import net.minecraft.world.IBlockAccess;
  16. import net.minecraft.world.World;
  17. import net.minecraftforge.fml.relauncher.Side;
  18. import net.minecraftforge.fml.relauncher.SideOnly;
  19.  
  20. public class BlockGrass extends Block implements IGrowable
  21. {
  22. public static final PropertyBool SNOWY = PropertyBool.create("snowy");
  23.  
  24. protected BlockGrass()
  25. {
  26. super(Material.GRASS);
  27. this.setDefaultState(this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)));
  28. this.setTickRandomly(true);
  29. this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
  30. }
  31.  
  32. /**
  33. * Get the actual Block state of this Block at the given position. This applies properties not visible in the
  34. * metadata, such as fence connections.
  35. */
  36. public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
  37. {
  38. Block block = worldIn.getBlockState(pos.up()).getBlock();
  39. return state.withProperty(SNOWY, Boolean.valueOf(block == Blocks.SNOW || block == Blocks.SNOW_LAYER));
  40. }
  41.  
  42. public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
  43. {
  44. if (!worldIn.isRemote)
  45. {
  46. if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
  47. {
  48. worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
  49. }
  50. else
  51. {
  52. if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
  53. {
  54. for (int i = 0; i < 4; ++i)
  55. {
  56. BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
  57.  
  58. if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
  59. {
  60. return;
  61. }
  62.  
  63. IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
  64. IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
  65.  
  66. if (iblockstate1.getBlock() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
  67. {
  68. worldIn.setBlockState(blockpos, Blocks.GRASS.getDefaultState());
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75.  
  76. /**
  77. * Get the Item that this Block should drop when harvested.
  78. */
  79. @Nullable
  80. public Item getItemDropped(IBlockState state, Random rand, int fortune)
  81. {
  82. return Blocks.DIRT.getItemDropped(Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
  83. }
  84.  
  85. /**
  86. * Whether this IGrowable can grow
  87. */
  88. public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
  89. {
  90. return true;
  91. }
  92.  
  93. public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
  94. {
  95. return true;
  96. }
  97.  
  98. public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
  99. {
  100. BlockPos blockpos = pos.up();
  101.  
  102. for (int i = 0; i < 128; ++i)
  103. {
  104. BlockPos blockpos1 = blockpos;
  105. int j = 0;
  106.  
  107. while (true)
  108. {
  109. if (j >= i / 16)
  110. {
  111. if (worldIn.isAirBlock(blockpos1))
  112. {
  113. if (rand.nextInt(8) == 0)
  114. {
  115. worldIn.getBiome(blockpos1).plantFlower(worldIn, rand, blockpos1);
  116. }
  117. else
  118. {
  119. IBlockState iblockstate1 = Blocks.TALLGRASS.getDefaultState().withProperty(BlockTallGrass.TYPE, BlockTallGrass.EnumType.GRASS);
  120.  
  121. if (Blocks.TALLGRASS.canBlockStay(worldIn, blockpos1, iblockstate1))
  122. {
  123. worldIn.setBlockState(blockpos1, iblockstate1, 3);
  124. }
  125. }
  126. }
  127.  
  128. break;
  129. }
  130.  
  131. blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
  132.  
  133. if (worldIn.getBlockState(blockpos1.down()).getBlock() != Blocks.GRASS || worldIn.getBlockState(blockpos1).isNormalCube())
  134. {
  135. break;
  136. }
  137.  
  138. ++j;
  139. }
  140. }
  141. }
  142.  
  143. @SideOnly(Side.CLIENT)
  144. public BlockRenderLayer getBlockLayer()
  145. {
  146. return BlockRenderLayer.CUTOUT_MIPPED;
  147. }
  148.  
  149. /**
  150. * Convert the BlockState into the correct metadata value
  151. */
  152. public int getMetaFromState(IBlockState state)
  153. {
  154. return 0;
  155. }
  156.  
  157. protected BlockStateContainer createBlockState()
  158. {
  159. return new BlockStateContainer(this, new IProperty[] {SNOWY});
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement