Guest User

Untitled

a guest
Oct 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. package com.ubempire.map;
  2.  
  3. import java.util.Random;
  4. import org.bukkit.Chunk;
  5. import org.bukkit.Material;
  6. import org.bukkit.World;
  7. import org.bukkit.block.Block;
  8. import org.bukkit.generator.BlockPopulator;
  9.  
  10. public class TreePopulator extends BlockPopulator {
  11. public TreePopulator(){
  12. }
  13.  
  14. @Override
  15. public void populate(World world, Random random, Chunk chunk) {
  16. int centerX = (chunk.getX() << 4) + random.nextInt(16);
  17. int centerZ = (chunk.getZ() << 4) + random.nextInt(16);
  18.  
  19. int chance = 0;
  20.  
  21. byte data = 0;
  22. int height = 4 + random.nextInt(3);
  23. int multiplier = 1;
  24.  
  25. if(random.nextBoolean()){
  26. data = 2;
  27. height = 5 + random.nextInt(3);;
  28. }
  29.  
  30. switch(world.getBlockAt(centerX, 0, centerZ).getBiome()){
  31. case FOREST:
  32. chance = 160;
  33. multiplier = 8;
  34. break;
  35. case PLAINS:
  36. chance = 40;
  37. break;
  38. case RAINFOREST:
  39. chance = 200;
  40. multiplier = 20;
  41. break;
  42. case SAVANNA:
  43. chance = 20;
  44. break;
  45. case SEASONAL_FOREST:
  46. chance = 175;
  47. multiplier = 12;
  48. break;
  49. case SHRUBLAND:
  50. chance = 60;
  51. break;
  52. case SWAMPLAND:
  53. chance = 120;
  54. break;
  55. case TAIGA:
  56. chance = 120;
  57. data = 1;
  58. height = 8 + random.nextInt(3);
  59. multiplier = 3;
  60. break;
  61. case TUNDRA:
  62. chance = 5;
  63. data = 1;
  64. height = 7 + random.nextInt(3);
  65. break;
  66. }
  67.  
  68. for(int i = 0; i < multiplier; i++){
  69. if(random.nextInt(200) < chance){
  70. int x = (chunk.getX() << 4) + random.nextInt(16);
  71. int z = (chunk.getZ() << 4) + random.nextInt(16);
  72. int centerY = world.getHighestBlockYAt(x, z) - 1;
  73. Block sourceBlock = world.getBlockAt(x, centerY, z);
  74. if(sourceBlock.getType() == Material.GRASS){
  75. if(data == 3){
  76.  
  77. }
  78. else{
  79. world.getBlockAt(x, centerY + height + 1, z).setTypeIdAndData(18, data, true);
  80. for(int j = 0; j < 4; j++){
  81. world.getBlockAt(x, centerY + height + 1 - j, z - 1).setTypeIdAndData(18, data, true);
  82. world.getBlockAt(x, centerY + height + 1 - j, z + 1).setTypeIdAndData(18, data, true);
  83. world.getBlockAt(x - 1, centerY + height + 1 - j, z).setTypeIdAndData(18, data, true);
  84. world.getBlockAt(x + 1, centerY + height + 1 - j, z).setTypeIdAndData(18, data, true);
  85. }
  86.  
  87. if(random.nextBoolean()) world.getBlockAt(x + 1, centerY + height, z + 1).setTypeIdAndData(18, data, true);
  88. if(random.nextBoolean()) world.getBlockAt(x + 1, centerY + height, z - 1).setTypeIdAndData(18, data, true);
  89. if(random.nextBoolean()) world.getBlockAt(x - 1, centerY + height, z + 1).setTypeIdAndData(18, data, true);
  90. if(random.nextBoolean()) world.getBlockAt(x - 1, centerY + height, z - 1).setTypeIdAndData(18, data, true);
  91.  
  92. world.getBlockAt(x + 1, centerY + height - 1, z + 1).setTypeIdAndData(18, data, true);
  93. world.getBlockAt(x + 1, centerY + height - 1, z - 1).setTypeIdAndData(18, data, true);
  94. world.getBlockAt(x - 1, centerY + height - 1, z + 1).setTypeIdAndData(18, data, true);
  95. world.getBlockAt(x - 1, centerY + height - 1, z - 1).setTypeIdAndData(18, data, true);
  96. world.getBlockAt(x + 1, centerY + height - 2, z + 1).setTypeIdAndData(18, data, true);
  97. world.getBlockAt(x + 1, centerY + height - 2, z - 1).setTypeIdAndData(18, data, true);
  98. world.getBlockAt(x - 1, centerY + height - 2, z + 1).setTypeIdAndData(18, data, true);
  99. world.getBlockAt(x - 1, centerY + height - 2, z - 1).setTypeIdAndData(18, data, true);
  100.  
  101. for(int j = 0; j < 2; j++){
  102. for(int k = -2; k <= 2; k++){
  103. for(int l = -2; l <= 2; l++){
  104. world.getBlockAt(x + k, centerY + height - 1 - j, z + l).setTypeIdAndData(18, data, true);
  105. }
  106. }
  107. }
  108.  
  109. for(int j = 0; j < 2; j++){
  110. if(random.nextBoolean()) world.getBlockAt(x + 2, centerY + height - 1 - j, z + 2).setTypeIdAndData(0, (byte) 0, true);
  111. if(random.nextBoolean()) world.getBlockAt(x + 2, centerY + height - 1 - j, z - 2).setTypeIdAndData(0, (byte) 0, true);
  112. if(random.nextBoolean()) world.getBlockAt(x - 2, centerY + height - 1 - j, z + 2).setTypeIdAndData(0, (byte) 0, true);
  113. if(random.nextBoolean()) world.getBlockAt(x - 2, centerY + height - 1 - j, z - 2).setTypeIdAndData(0, (byte) 0, true);
  114. }
  115. }
  116. for(int y = 1; y <= height; y++){
  117. world.getBlockAt(x, centerY + y, z).setTypeIdAndData(17, data, true);
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
Add Comment
Please, Sign In to add comment