Guest User

Untitled

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