Advertisement
Guest User

Untitled

a guest
Jul 27th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. package net.phytopia.mod.biome.features;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockSapling;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.util.Direction;
  10. import net.minecraft.world.World;
  11. import net.minecraft.world.gen.feature.WorldGenAbstractTree;
  12. import net.minecraftforge.common.util.ForgeDirection;
  13. import net.phytopia.mod.Phytopia;
  14.  
  15. public class WorldGenWeirwoodTree extends WorldGenAbstractTree {
  16.  
  17. public WorldGenWeirwoodTree() {
  18. super(false);
  19. }
  20.  
  21. @Override
  22. public boolean generate(World world, Random random, int x, int y, int z) {
  23.  
  24. while (world.isAirBlock(x, y, z) && y >2) {
  25. y--;
  26. }
  27.  
  28. Block block = world.getBlock(x, y, z);
  29.  
  30. if (block != Blocks.grass && block != Blocks.dirt) {
  31. return false;
  32. }else{
  33. for (int i = -2; i <= 2; i++){
  34. for (int j = -2; j <= 2; j++) {
  35. if (world.isAirBlock(x + i, y - 1, z + j) && world.isAirBlock(x + i, y - 2, z +j) && !world.isAirBlock(x + i, y, z + j)) {
  36. return false;
  37. }
  38. }
  39. }
  40.  
  41. int baselength = 4 + random.nextInt(6);
  42. int branches = 2 + random.nextInt(4);
  43.  
  44. int h = 1;
  45.  
  46. block.onPlantGrow(world, x, y - 1, z, z, y, z);
  47.  
  48. for (int i = 0; i < baselength; i++) {
  49. buildBlock(world, x, y + h, z, Phytopia.blockLog, 0);
  50. h++;
  51. }
  52.  
  53. int c = 1;
  54. for (int i = 0; i < branches; i++) {
  55. generateBranch(world, random, x, y + h, z, c);
  56. c++;
  57. h+=2;
  58. }
  59.  
  60. generateTop(world, x, y + h, z);
  61. return true;
  62. }
  63.  
  64. }
  65.  
  66. public void generateTop(World world, int x, int y, int z) {
  67. for (int i = -1; i <2; i++) {
  68. for (int j = -1; j < 2; j++) {
  69. buildBlock(world, x + i, y, z + j, Phytopia.blockLeaf, 0);
  70. }
  71. }
  72. buildBlock(world, x, y + 1, z, Phytopia.blockLog, 0);
  73. buildBlock(world, x + 1, y + 1, z, Phytopia.blockLeaf, 0);
  74. buildBlock(world, x - 1, y + 1, z, Phytopia.blockLeaf, 0);
  75. buildBlock(world, x, y + 1, z - 1, Phytopia.blockLeaf, 0);
  76. buildBlock(world, x, y + 1, z + 1, Phytopia.blockLeaf, 0);
  77. buildBlock(world, x, y + 2, z, Phytopia.blockLeaf, 0);
  78.  
  79.  
  80. }
  81.  
  82. public void generateBranch(World world, Random random, int x, int y, int z, int p) {
  83. for (int i = -1; i < 2; i++) {
  84. for (int j = -1; j < 2; j++) {
  85. buildBlock(world, x + i, y, z + j, Phytopia.blockLeaf, 0);
  86. }
  87. }
  88. buildBlock(world, x + 1, y + 1, z, Phytopia.blockLeaf, 0);
  89. buildBlock(world, x - 1, y + 1, z, Phytopia.blockLeaf, 0);
  90. buildBlock(world, x, y + 1, z - 1, Phytopia.blockLeaf, 0);
  91. buildBlock(world, x, y + 1, z + 1, Phytopia.blockLeaf, 0);
  92. buildBlock(world, x, y, z, Phytopia.blockLog, 0);
  93. buildBlock(world, x, y + 1, z, Phytopia.blockLog, 0);
  94. }
  95.  
  96. public void buildBlock(World world, int x, int y, int z, Block block, int meta) {
  97. if (world.isAirBlock(x, y, z) || world.getBlock(x, y, z).isLeaves(world, x, y, z)) {
  98. world.setBlock(x, y, z, block, meta, 2);
  99. }
  100.  
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement