Advertisement
Guest User

WorldGenMangoTree.java

a guest
Apr 9th, 2016
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.72 KB | None | 0 0
  1. package com.tristanvo.mod.Generation;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.tristanvo.mod.mod;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.BlockSapling;
  9. import net.minecraft.init.Blocks;
  10. import net.minecraft.util.Direction;
  11. import net.minecraft.world.World;
  12. import net.minecraft.world.gen.feature.WorldGenAbstractTree;
  13. import net.minecraftforge.common.util.ForgeDirection;
  14.  
  15. public class WorldGenMangoTree extends WorldGenAbstractTree
  16. {
  17. private final int minTreeHeight;
  18. private final int randomTreeHeight;
  19.  
  20. private final boolean vinesGrow;
  21.  
  22. private final Block wood;
  23. private final Block leaves;
  24.  
  25. private final int metaWood;
  26. private final int metaLeaves;
  27.  
  28. public WorldGenMangoTree(Block wood, Block leaves, int metaWood, int metaLeaves)
  29. {
  30. this(wood, leaves, metaWood, metaLeaves, false, 4, 3, false);
  31. }
  32.  
  33. public WorldGenMangoTree(Block wood, Block leaves, int metaWood, int metaLeaves, boolean doBlockNotify, int minTreeHeight, int randomTreeHeight, boolean vinesGrow)
  34. {
  35. super(doBlockNotify);
  36.  
  37. this.wood = wood;
  38. this.leaves = leaves;
  39.  
  40. this.minTreeHeight = minTreeHeight;
  41. this.randomTreeHeight = randomTreeHeight;
  42.  
  43. this.metaWood = metaWood;
  44. this.metaLeaves = metaLeaves;
  45. this.vinesGrow = vinesGrow;
  46. }
  47.  
  48. public boolean generate(World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_)
  49. {
  50. int l = p_76484_2_.nextInt(3) + this.minTreeHeight;
  51. boolean flag = true;
  52.  
  53. if (p_76484_4_ >= 1 && p_76484_4_ + l + 1 <= 256)
  54. {
  55. byte b0;
  56. int k1;
  57. Block block;
  58.  
  59. for (int i1 = p_76484_4_; i1 <= p_76484_4_ + 1 + l; ++i1)
  60. {
  61. b0 = 1;
  62.  
  63. if (i1 == p_76484_4_)
  64. {
  65. b0 = 0;
  66. }
  67.  
  68. if (i1 >= p_76484_4_ + 1 + l - 2)
  69. {
  70. b0 = 2;
  71. }
  72.  
  73. for (int j1 = p_76484_3_ - b0; j1 <= p_76484_3_ + b0 && flag; ++j1)
  74. {
  75. for (k1 = p_76484_5_ - b0; k1 <= p_76484_5_ + b0 && flag; ++k1)
  76. {
  77. if (i1 >= 0 && i1 < 256)
  78. {
  79. block = p_76484_1_.getBlock(j1, i1, k1);
  80.  
  81. if (!this.isReplaceable(p_76484_1_, j1, i1, k1))
  82. {
  83. flag = false;
  84. }
  85. }
  86. else
  87. {
  88. flag = false;
  89. }
  90. }
  91. }
  92. }
  93.  
  94. if (!flag)
  95. {
  96. return false;
  97. }
  98. else
  99. {
  100. Block block2 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_);
  101.  
  102. boolean isSoil = block2.canSustainPlant(p_76484_1_, p_76484_3_, p_76484_4_ - 1, p_76484_5_, ForgeDirection.UP, (BlockSapling)mod.mangoSapling);
  103. if (isSoil && p_76484_4_ < 256 - l - 1)
  104. {
  105. block2.onPlantGrow(p_76484_1_, p_76484_3_, p_76484_4_ - 1, p_76484_5_, p_76484_3_, p_76484_4_, p_76484_5_);
  106. b0 = 3;
  107. byte b1 = 0;
  108. int l1;
  109. int i2;
  110. int j2;
  111. int i3;
  112.  
  113. for (k1 = p_76484_4_ - b0 + l; k1 <= p_76484_4_ + l; ++k1)
  114. {
  115. i3 = k1 - (p_76484_4_ + l);
  116. l1 = b1 + 1 - i3 / 2;
  117.  
  118. for (i2 = p_76484_3_ - l1; i2 <= p_76484_3_ + l1; ++i2)
  119. {
  120. j2 = i2 - p_76484_3_;
  121.  
  122. for (int k2 = p_76484_5_ - l1; k2 <= p_76484_5_ + l1; ++k2)
  123. {
  124. int l2 = k2 - p_76484_5_;
  125.  
  126. if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || p_76484_2_.nextInt(2) != 0 && i3 != 0)
  127. {
  128. Block block1 = p_76484_1_.getBlock(i2, k1, k2);
  129.  
  130. if (block1.isAir(p_76484_1_, i2, k1, k2) || block1.isLeaves(p_76484_1_, i2, k1, k2))
  131. {
  132. this.setBlockAndNotifyAdequately(p_76484_1_, i2, k1, k2, mod.mangoLeaf, this.metaLeaves);
  133. }
  134. }
  135. }
  136. }
  137. }
  138.  
  139. for (k1 = 0; k1 < l; ++k1)
  140. {
  141. block = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_);
  142.  
  143. if (block.isAir(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_) || block.isLeaves(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_))
  144. {
  145. this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_, mod.mangoLog, this.metaWood);
  146.  
  147. if (this.vinesGrow && k1 > 0)
  148. {
  149. if (p_76484_2_.nextInt(3) > 0 && p_76484_1_.isAirBlock(p_76484_3_ - 1, p_76484_4_ + k1, p_76484_5_))
  150. {
  151. this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_ - 1, p_76484_4_ + k1, p_76484_5_, Blocks.vine, 8);
  152. }
  153.  
  154. if (p_76484_2_.nextInt(3) > 0 && p_76484_1_.isAirBlock(p_76484_3_ + 1, p_76484_4_ + k1, p_76484_5_))
  155. {
  156. this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_ + 1, p_76484_4_ + k1, p_76484_5_, Blocks.vine, 2);
  157. }
  158.  
  159. if (p_76484_2_.nextInt(3) > 0 && p_76484_1_.isAirBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_ - 1))
  160. {
  161. this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_ - 1, Blocks.vine, 1);
  162. }
  163.  
  164. if (p_76484_2_.nextInt(3) > 0 && p_76484_1_.isAirBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_ + 1))
  165. {
  166. this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_ + 1, Blocks.vine, 4);
  167. }
  168. }
  169. }
  170. }
  171.  
  172. if (this.vinesGrow)
  173. {
  174. for (k1 = p_76484_4_ - 3 + l; k1 <= p_76484_4_ + l; ++k1)
  175. {
  176. i3 = k1 - (p_76484_4_ + l);
  177. l1 = 2 - i3 / 2;
  178.  
  179. for (i2 = p_76484_3_ - l1; i2 <= p_76484_3_ + l1; ++i2)
  180. {
  181. for (j2 = p_76484_5_ - l1; j2 <= p_76484_5_ + l1; ++j2)
  182. {
  183. if (p_76484_1_.getBlock(i2, k1, j2).isLeaves(p_76484_1_, i2, k1, j2))
  184. {
  185. if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(i2 - 1, k1, j2).isAir(p_76484_1_, i2 - 1, k1, j2))
  186. {
  187. this.growVines(p_76484_1_, i2 - 1, k1, j2, 8);
  188. }
  189.  
  190. if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(i2 + 1, k1, j2).isAir(p_76484_1_, i2 + 1, k1, j2))
  191. {
  192. this.growVines(p_76484_1_, i2 + 1, k1, j2, 2);
  193. }
  194.  
  195. if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(i2, k1, j2 - 1).isAir(p_76484_1_, i2, k1, j2 - 1))
  196. {
  197. this.growVines(p_76484_1_, i2, k1, j2 - 1, 1);
  198. }
  199.  
  200. if (p_76484_2_.nextInt(4) == 0 && p_76484_1_.getBlock(i2, k1, j2 + 1).isAir(p_76484_1_, i2, k1, j2 + 1))
  201. {
  202. this.growVines(p_76484_1_, i2, k1, j2 + 1, 4);
  203. }
  204. }
  205. }
  206. }
  207. }
  208.  
  209. if (p_76484_2_.nextInt(5) == 0 && l > 5)
  210. {
  211. for (k1 = 0; k1 < 2; ++k1)
  212. {
  213. for (i3 = 0; i3 < 4; ++i3)
  214. {
  215. if (p_76484_2_.nextInt(4 - k1) == 0)
  216. {
  217. l1 = p_76484_2_.nextInt(3);
  218. this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_ + Direction.offsetX[Direction.rotateOpposite[i3]], p_76484_4_ + l - 5 + k1, p_76484_5_ + Direction.offsetZ[Direction.rotateOpposite[i3]], Blocks.cocoa, l1 << 2 | i3);
  219. }
  220. }
  221. }
  222. }
  223. }
  224.  
  225. return true;
  226. }
  227. else
  228. {
  229. return false;
  230. }
  231. }
  232. }
  233. else
  234. {
  235. return false;
  236. }
  237. }
  238.  
  239. /**
  240. * Grows vines downward from the given block for a given length. Args: World, x, starty, z, vine-length
  241. */
  242. private void growVines(World p_76529_1_, int p_76529_2_, int p_76529_3_, int p_76529_4_, int p_76529_5_)
  243. {
  244. this.setBlockAndNotifyAdequately(p_76529_1_, p_76529_2_, p_76529_3_, p_76529_4_, Blocks.vine, p_76529_5_);
  245. int i1 = 4;
  246.  
  247. while (true)
  248. {
  249. --p_76529_3_;
  250.  
  251. if (!p_76529_1_.getBlock(p_76529_2_, p_76529_3_, p_76529_4_).isAir(p_76529_1_, p_76529_2_, p_76529_3_, p_76529_4_) || i1 <= 0)
  252. {
  253. return;
  254. }
  255.  
  256. this.setBlockAndNotifyAdequately(p_76529_1_, p_76529_2_, p_76529_3_, p_76529_4_, Blocks.vine, p_76529_5_);
  257. --i1;
  258. }
  259. }
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement