SpazzMods

worldgenTree

Jul 19th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.89 KB | None | 0 0
  1. public class WorldGenTrees extends WorldGenAbstractTree
  2. {
  3. private static final IBlockState DEFAULT_TRUNK = Blocks.LOG.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.OAK);
  4. private static final IBlockState DEFAULT_LEAF = Blocks.LEAVES.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
  5. /** The minimum height of a generated tree. */
  6. private final int minTreeHeight;
  7. /** True if this tree should grow Vines. */
  8. private final boolean vinesGrow;
  9. /** The metadata value of the wood to use in tree generation. */
  10. private final IBlockState metaWood;
  11. /** The metadata value of the leaves to use in tree generation. */
  12. private final IBlockState metaLeaves;
  13.  
  14. public WorldGenTrees(boolean p_i2027_1_)
  15. {
  16. this(p_i2027_1_, 4, DEFAULT_TRUNK, DEFAULT_LEAF, false);
  17. }
  18.  
  19. public WorldGenTrees(boolean p_i46446_1_, int p_i46446_2_, IBlockState p_i46446_3_, IBlockState p_i46446_4_, boolean p_i46446_5_)
  20. {
  21. super(p_i46446_1_);
  22. this.minTreeHeight = p_i46446_2_;
  23. this.metaWood = p_i46446_3_;
  24. this.metaLeaves = p_i46446_4_;
  25. this.vinesGrow = p_i46446_5_;
  26. }
  27.  
  28. public boolean generate(World worldIn, Random rand, BlockPos position)
  29. {
  30. int i = rand.nextInt(3) + this.minTreeHeight;
  31. boolean flag = true;
  32.  
  33. if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight())
  34. {
  35. for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
  36. {
  37. int k = 1;
  38.  
  39. if (j == position.getY())
  40. {
  41. k = 0;
  42. }
  43.  
  44. if (j >= position.getY() + 1 + i - 2)
  45. {
  46. k = 2;
  47. }
  48.  
  49. BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
  50.  
  51. for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
  52. {
  53. for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
  54. {
  55. if (j >= 0 && j < worldIn.getHeight())
  56. {
  57. if (!this.isReplaceable(worldIn,blockpos$mutableblockpos.setPos(l, j, i1)))
  58. {
  59. flag = false;
  60. }
  61. }
  62. else
  63. {
  64. flag = false;
  65. }
  66. }
  67. }
  68. }
  69.  
  70. if (!flag)
  71. {
  72. return false;
  73. }
  74. else
  75. {
  76. IBlockState state = worldIn.getBlockState(position.down());
  77.  
  78. if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling)Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1)
  79. {
  80. this.setDirtAt(worldIn, position.down());
  81. int k2 = 3;
  82. int l2 = 0;
  83.  
  84. for (int i3 = position.getY() - k2 + i; i3 <= position.getY() + i; ++i3)
  85. {
  86. int i4 = i3 - (position.getY() + i);
  87. int j1 = l2 + 1 - i4 / 2;
  88.  
  89. for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1)
  90. {
  91. int l1 = k1 - position.getX();
  92.  
  93. for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2)
  94. {
  95. int j2 = i2 - position.getZ();
  96.  
  97. if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0 && i4 != 0)
  98. {
  99. BlockPos blockpos = new BlockPos(k1, i3, i2);
  100. state = worldIn.getBlockState(blockpos);
  101.  
  102. if (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getMaterial() == Material.VINE)
  103. {
  104. this.setBlockAndNotifyAdequately(worldIn, blockpos, this.metaLeaves);
  105. }
  106. }
  107. }
  108. }
  109. }
  110.  
  111. for (int j3 = 0; j3 < i; ++j3)
  112. {
  113. BlockPos upN = position.up(j3);
  114. state = worldIn.getBlockState(upN);
  115.  
  116. if (state.getBlock().isAir(state, worldIn, upN) || state.getBlock().isLeaves(state, worldIn, upN) || state.getMaterial() == Material.VINE)
  117. {
  118. this.setBlockAndNotifyAdequately(worldIn, position.up(j3), this.metaWood);
  119.  
  120. if (this.vinesGrow && j3 > 0)
  121. {
  122. if (rand.nextInt(3) > 0 && worldIn.isAirBlock(position.add(-1, j3, 0)))
  123. {
  124. this.addVine(worldIn, position.add(-1, j3, 0), BlockVine.EAST);
  125. }
  126.  
  127. if (rand.nextInt(3) > 0 && worldIn.isAirBlock(position.add(1, j3, 0)))
  128. {
  129. this.addVine(worldIn, position.add(1, j3, 0), BlockVine.WEST);
  130. }
  131.  
  132. if (rand.nextInt(3) > 0 && worldIn.isAirBlock(position.add(0, j3, -1)))
  133. {
  134. this.addVine(worldIn, position.add(0, j3, -1), BlockVine.SOUTH);
  135. }
  136.  
  137. if (rand.nextInt(3) > 0 && worldIn.isAirBlock(position.add(0, j3, 1)))
  138. {
  139. this.addVine(worldIn, position.add(0, j3, 1), BlockVine.NORTH);
  140. }
  141. }
  142. }
  143. }
  144.  
  145. if (this.vinesGrow)
  146. {
  147. for (int k3 = position.getY() - 3 + i; k3 <= position.getY() + i; ++k3)
  148. {
  149. int j4 = k3 - (position.getY() + i);
  150. int k4 = 2 - j4 / 2;
  151. BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos();
  152.  
  153. for (int l4 = position.getX() - k4; l4 <= position.getX() + k4; ++l4)
  154. {
  155. for (int i5 = position.getZ() - k4; i5 <= position.getZ() + k4; ++i5)
  156. {
  157. blockpos$mutableblockpos1.setPos(l4, k3, i5);
  158.  
  159. state = worldIn.getBlockState(blockpos$mutableblockpos1);
  160. if (state.getBlock().isLeaves(state, worldIn, blockpos$mutableblockpos1))
  161. {
  162. BlockPos blockpos2 = blockpos$mutableblockpos1.west();
  163. BlockPos blockpos3 = blockpos$mutableblockpos1.east();
  164. BlockPos blockpos4 = blockpos$mutableblockpos1.north();
  165. BlockPos blockpos1 = blockpos$mutableblockpos1.south();
  166.  
  167. if (rand.nextInt(4) == 0 && worldIn.isAirBlock(blockpos2))
  168. {
  169. this.addHangingVine(worldIn, blockpos2, BlockVine.EAST);
  170. }
  171.  
  172. if (rand.nextInt(4) == 0 && worldIn.isAirBlock(blockpos3))
  173. {
  174. this.addHangingVine(worldIn, blockpos3, BlockVine.WEST);
  175. }
  176.  
  177. if (rand.nextInt(4) == 0 && worldIn.isAirBlock(blockpos4))
  178. {
  179. this.addHangingVine(worldIn, blockpos4, BlockVine.SOUTH);
  180. }
  181.  
  182. if (rand.nextInt(4) == 0 && worldIn.isAirBlock(blockpos1))
  183. {
  184. this.addHangingVine(worldIn, blockpos1, BlockVine.NORTH);
  185. }
  186. }
  187. }
  188. }
  189. }
  190.  
  191. if (rand.nextInt(5) == 0 && i > 5)
  192. {
  193. for (int l3 = 0; l3 < 2; ++l3)
  194. {
  195. for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  196. {
  197. if (rand.nextInt(4 - l3) == 0)
  198. {
  199. EnumFacing enumfacing1 = enumfacing.getOpposite();
  200. this.placeCocoa(worldIn, rand.nextInt(3), position.add(enumfacing1.getFrontOffsetX(), i - 5 + l3, enumfacing1.getFrontOffsetZ()), enumfacing);
  201. }
  202. }
  203. }
  204. }
  205. }
  206.  
  207. return true;
  208. }
  209. else
  210. {
  211. return false;
  212. }
  213. }
  214. }
  215. else
  216. {
  217. return false;
  218. }
  219. }
  220.  
  221. private void placeCocoa(World worldIn, int p_181652_2_, BlockPos pos, EnumFacing side)
  222. {
  223. this.setBlockAndNotifyAdequately(worldIn, pos, Blocks.COCOA.getDefaultState().withProperty(BlockCocoa.AGE, Integer.valueOf(p_181652_2_)).withProperty(BlockCocoa.FACING, side));
  224. }
  225.  
  226. private void addVine(World worldIn, BlockPos pos, PropertyBool prop)
  227. {
  228. this.setBlockAndNotifyAdequately(worldIn, pos, Blocks.VINE.getDefaultState().withProperty(prop, Boolean.valueOf(true)));
  229. }
  230.  
  231. private void addHangingVine(World worldIn, BlockPos pos, PropertyBool prop)
  232. {
  233. this.addVine(worldIn, pos, prop);
  234. int i = 4;
  235.  
  236. for (pos = pos.down(); worldIn.isAirBlock(pos) && i > 0; --i)
  237. {
  238. this.addVine(worldIn, pos, prop);
  239. pos = pos.down();
  240. }
  241. }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment