Advertisement
Guest User

Untitled

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