Advertisement
Guest User

ModWorldGenBanana

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