Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ubempire.map;
- import java.util.Random;
- import org.bukkit.Chunk;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.generator.BlockPopulator;
- public class TreePopulator extends BlockPopulator {
- public TreePopulator(){
- }
- @Override
- public void populate(World world, Random random, Chunk chunk) {
- int centerX = (chunk.getX() << 4) + random.nextInt(16);
- int centerZ = (chunk.getZ() << 4) + random.nextInt(16);
- int chance = 0;
- byte data = 0;
- int height = 4 + random.nextInt(3);
- int multiplier = 1;
- if(random.nextBoolean()){
- data = 2;
- height = 5 + random.nextInt(3);;
- }
- switch(world.getBlockAt(centerX, 0, centerZ).getBiome()){
- case FOREST:
- chance = 160;
- multiplier = 8;
- break;
- case PLAINS:
- chance = 40;
- break;
- case RAINFOREST:
- chance = 200;
- multiplier = 20;
- break;
- case SAVANNA:
- chance = 20;
- break;
- case SEASONAL_FOREST:
- chance = 175;
- multiplier = 12;
- break;
- case SHRUBLAND:
- chance = 60;
- break;
- case SWAMPLAND:
- chance = 120;
- break;
- case TAIGA:
- chance = 120;
- data = 1;
- height = 8 + random.nextInt(3);
- multiplier = 3;
- break;
- case TUNDRA:
- chance = 5;
- data = 1;
- height = 7 + random.nextInt(3);
- break;
- }
- for(int i = 0; i < multiplier; i++){
- if(random.nextInt(200) < chance){
- int x = (chunk.getX() << 4) + random.nextInt(16);
- int z = (chunk.getZ() << 4) + random.nextInt(16);
- int centerY = world.getHighestBlockYAt(x, z) - 1;
- Block sourceBlock = world.getBlockAt(x, centerY, z);
- if(sourceBlock.getType() == Material.GRASS){
- if(data == 3){
- }
- else{
- world.getBlockAt(x, centerY + height + 1, z).setTypeIdAndData(18, data, true);
- for(int j = 0; j < 4; j++){
- world.getBlockAt(x, centerY + height + 1 - j, z - 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x, centerY + height + 1 - j, z + 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x - 1, centerY + height + 1 - j, z).setTypeIdAndData(18, data, true);
- world.getBlockAt(x + 1, centerY + height + 1 - j, z).setTypeIdAndData(18, data, true);
- }
- if(random.nextBoolean()) world.getBlockAt(x + 1, centerY + height, z + 1).setTypeIdAndData(18, data, true);
- if(random.nextBoolean()) world.getBlockAt(x + 1, centerY + height, z - 1).setTypeIdAndData(18, data, true);
- if(random.nextBoolean()) world.getBlockAt(x - 1, centerY + height, z + 1).setTypeIdAndData(18, data, true);
- if(random.nextBoolean()) world.getBlockAt(x - 1, centerY + height, z - 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x + 1, centerY + height - 1, z + 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x + 1, centerY + height - 1, z - 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x - 1, centerY + height - 1, z + 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x - 1, centerY + height - 1, z - 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x + 1, centerY + height - 2, z + 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x + 1, centerY + height - 2, z - 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x - 1, centerY + height - 2, z + 1).setTypeIdAndData(18, data, true);
- world.getBlockAt(x - 1, centerY + height - 2, z - 1).setTypeIdAndData(18, data, true);
- for(int j = 0; j < 2; j++){
- for(int k = -2; k <= 2; k++){
- for(int l = -2; l <= 2; l++){
- world.getBlockAt(x + k, centerY + height - 1 - j, z + l).setTypeIdAndData(18, data, true);
- }
- }
- }
- for(int j = 0; j < 2; j++){
- if(random.nextBoolean()) world.getBlockAt(x + 2, centerY + height - 1 - j, z + 2).setTypeIdAndData(0, (byte) 0, true);
- if(random.nextBoolean()) world.getBlockAt(x + 2, centerY + height - 1 - j, z - 2).setTypeIdAndData(0, (byte) 0, true);
- if(random.nextBoolean()) world.getBlockAt(x - 2, centerY + height - 1 - j, z + 2).setTypeIdAndData(0, (byte) 0, true);
- if(random.nextBoolean()) world.getBlockAt(x - 2, centerY + height - 1 - j, z - 2).setTypeIdAndData(0, (byte) 0, true);
- }
- }
- for(int y = 1; y <= height; y++){
- world.getBlockAt(x, centerY + y, z).setTypeIdAndData(17, data, true);
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment