use of cn.nukkit.level.generator.object.BasicGenerator in project Nukkit by Nukkit.
the class BlockSapling method onActivate.
public boolean onActivate(Item item, Player player) {
if (item.getId() == Item.DYE && item.getDamage() == 0x0F) {
// BoneMeal
if ((player.gamemode & 0x01) == 0) {
item.count--;
}
this.level.addParticle(new BoneMealParticle(this));
if (ThreadLocalRandom.current().nextFloat() >= 0.45) {
return true;
}
BasicGenerator generator = null;
boolean bigTree = false;
int x = 0;
int z = 0;
switch(this.getDamage()) {
case JUNGLE:
loop: for (x = 0; x >= -1; --x) {
for (z = 0; z >= -1; --z) {
if (this.findSaplings(x, z, JUNGLE)) {
generator = new ObjectJungleBigTree(10, 20, new BlockWood(BlockWood.JUNGLE), new BlockLeaves(BlockLeaves.JUNGLE));
bigTree = true;
break loop;
}
}
}
if (!bigTree) {
generator = new NewJungleTree(4 + ThreadLocalRandom.current().nextInt(7));
}
break;
case ACACIA:
generator = new ObjectSavannaTree();
break;
case DARK_OAK:
bigTree = false;
loop: for (x = 0; x >= -1; --x) {
for (z = 0; z >= -1; --z) {
if (this.findSaplings(x, z, DARK_OAK)) {
generator = new ObjectDarkOakTree();
bigTree = true;
break loop;
}
}
}
if (!bigTree) {
return false;
}
break;
// TODO: big spruce
default:
ObjectTree.growTree(this.getLevel(), (int) this.x, (int) this.y, (int) this.z, new NukkitRandom(), this.getDamage() & 0x07);
return true;
}
BlockAir air = new BlockAir();
if (bigTree) {
this.level.setBlock(this.add(x, 0, z), air, true, false);
this.level.setBlock(this.add(x + 1, 0, z), air, true, false);
this.level.setBlock(this.add(x, 0, z + 1), air, true, false);
this.level.setBlock(this.add(x + 1, 0, z + 1), air, true, false);
} else {
this.level.setBlock(this, air, true, false);
}
if (!generator.generate(this.level, new NukkitRandom(), this.add(x, 0, z))) {
if (bigTree) {
this.level.setBlock(this.add(x, 0, z), this, true, false);
this.level.setBlock(this.add(x + 1, 0, z), this, true, false);
this.level.setBlock(this.add(x, 0, z + 1), this, true, false);
this.level.setBlock(this.add(x + 1, 0, z + 1), this, true, false);
} else {
this.level.setBlock(this, this, true, false);
}
}
return true;
}
return false;
}
Aggregations