2011-02-23 03:37:56 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftBlockChangeDelegate; // CraftBukkit
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public class WorldGenTrees extends WorldGenTreeAbstract implements BlockSapling.TreeGenerator { // CraftBukkit - add interface
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
private final int a;
|
|
|
|
private final boolean b;
|
|
|
|
private final int c;
|
|
|
|
private final int d;
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public WorldGenTrees(boolean flag) {
|
2012-03-01 11:49:23 +01:00
|
|
|
this(flag, 4, 0, 0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public WorldGenTrees(boolean flag, int i, int j, int k, boolean flag1) {
|
2011-11-20 09:01:14 +01:00
|
|
|
super(flag);
|
2012-03-01 11:49:23 +01:00
|
|
|
this.a = i;
|
|
|
|
this.c = j;
|
|
|
|
this.d = k;
|
|
|
|
this.b = flag1;
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
|
|
|
public boolean a(World world, Random random, int i, int j, int k) {
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Moved to generate
|
2013-11-04 14:07:38 +01:00
|
|
|
return this.generate(new CraftBlockChangeDelegate((org.bukkit.BlockChangeDelegate) world), random, i, j, k);
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean generate(CraftBlockChangeDelegate world, Random random, int i, int j, int k) {
|
2011-02-23 03:37:56 +01:00
|
|
|
// CraftBukkit end
|
2012-03-01 11:49:23 +01:00
|
|
|
int l = random.nextInt(3) + this.a;
|
2011-02-23 03:37:56 +01:00
|
|
|
boolean flag = true;
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if (j >= 1 && j + l + 1 <= 256) {
|
|
|
|
byte b0;
|
2013-11-04 14:07:38 +01:00
|
|
|
int i1;
|
|
|
|
Block block;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int j1 = j; j1 <= j + 1 + l; ++j1) {
|
2012-03-01 11:49:23 +01:00
|
|
|
b0 = 1;
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j1 == j) {
|
2011-11-20 09:01:14 +01:00
|
|
|
b0 = 0;
|
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j1 >= j + 1 + l - 2) {
|
2011-11-20 09:01:14 +01:00
|
|
|
b0 = 2;
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int k1 = i - b0; k1 <= i + b0 && flag; ++k1) {
|
|
|
|
for (i1 = k - b0; i1 <= k + b0 && flag; ++i1) {
|
|
|
|
if (j1 >= 0 && j1 < 256) {
|
|
|
|
block = world.getType(k1, j1, i1);
|
|
|
|
if (!this.a(block)) {
|
2011-11-20 09:01:14 +01:00
|
|
|
flag = false;
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
} else {
|
2011-02-23 03:37:56 +01:00
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (!flag) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
Block block1 = world.getType(i, j - 1, k);
|
|
|
|
|
|
|
|
if ((block1 == Blocks.GRASS || block1 == Blocks.DIRT || block1 == Blocks.SOIL) && j < 256 - l - 1) {
|
|
|
|
this.setType(world, i, j - 1, k, Blocks.DIRT);
|
2012-03-01 11:49:23 +01:00
|
|
|
b0 = 3;
|
|
|
|
byte b1 = 0;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
int l1;
|
2011-11-20 09:01:14 +01:00
|
|
|
int i2;
|
2012-03-01 11:49:23 +01:00
|
|
|
int j2;
|
|
|
|
int k2;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (i1 = j - b0 + l; i1 <= j + l; ++i1) {
|
|
|
|
k2 = i1 - (j + l);
|
|
|
|
l1 = b1 + 1 - k2 / 2;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (i2 = i - l1; i2 <= i + l1; ++i2) {
|
|
|
|
j2 = i2 - i;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int l2 = k - l1; l2 <= k + l1; ++l2) {
|
2012-03-01 11:49:23 +01:00
|
|
|
int i3 = l2 - k;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (Math.abs(j2) != l1 || Math.abs(i3) != l1 || random.nextInt(2) != 0 && k2 != 0) {
|
|
|
|
Block block2 = world.getType(i2, i1, l2);
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (block2.getMaterial() == Material.AIR || block2.getMaterial() == Material.LEAVES) {
|
|
|
|
this.setTypeAndData(world, i2, i1, l2, Blocks.LEAVES, this.d);
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (i1 = 0; i1 < l; ++i1) {
|
|
|
|
block = world.getType(i, j + i1, k);
|
|
|
|
if (block.getMaterial() == Material.AIR || block.getMaterial() == Material.LEAVES) {
|
|
|
|
this.setTypeAndData(world, i, j + i1, k, Blocks.LOG, this.c);
|
|
|
|
if (this.b && i1 > 0) {
|
|
|
|
if (random.nextInt(3) > 0 && world.isEmpty(i - 1, j + i1, k)) {
|
|
|
|
this.setTypeAndData(world, i - 1, j + i1, k, Blocks.VINE, 8);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (random.nextInt(3) > 0 && world.isEmpty(i + 1, j + i1, k)) {
|
|
|
|
this.setTypeAndData(world, i + 1, j + i1, k, Blocks.VINE, 2);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (random.nextInt(3) > 0 && world.isEmpty(i, j + i1, k - 1)) {
|
|
|
|
this.setTypeAndData(world, i, j + i1, k - 1, Blocks.VINE, 1);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (random.nextInt(3) > 0 && world.isEmpty(i, j + i1, k + 1)) {
|
|
|
|
this.setTypeAndData(world, i, j + i1, k + 1, Blocks.VINE, 4);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.b) {
|
2013-11-04 14:07:38 +01:00
|
|
|
for (i1 = j - 3 + l; i1 <= j + l; ++i1) {
|
|
|
|
k2 = i1 - (j + l);
|
|
|
|
l1 = 2 - k2 / 2;
|
|
|
|
|
|
|
|
for (i2 = i - l1; i2 <= i + l1; ++i2) {
|
|
|
|
for (j2 = k - l1; j2 <= k + l1; ++j2) {
|
|
|
|
if (world.getType(i2, i1, j2).getMaterial() == Material.LEAVES) {
|
|
|
|
if (random.nextInt(4) == 0 && world.getType(i2 - 1, i1, j2).getMaterial() == Material.AIR) {
|
|
|
|
this.a(world, i2 - 1, i1, j2, 8);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (random.nextInt(4) == 0 && world.getType(i2 + 1, i1, j2).getMaterial() == Material.AIR) {
|
|
|
|
this.a(world, i2 + 1, i1, j2, 2);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (random.nextInt(4) == 0 && world.getType(i2, i1, j2 - 1).getMaterial() == Material.AIR) {
|
|
|
|
this.a(world, i2, i1, j2 - 1, 1);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (random.nextInt(4) == 0 && world.getType(i2, i1, j2 + 1).getMaterial() == Material.AIR) {
|
|
|
|
this.a(world, i2, i1, j2 + 1, 4);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-09 17:11:56 +01:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
|
|
|
if (random.nextInt(5) == 0 && l > 5) {
|
2013-11-04 14:07:38 +01:00
|
|
|
for (i1 = 0; i1 < 2; ++i1) {
|
|
|
|
for (k2 = 0; k2 < 4; ++k2) {
|
|
|
|
if (random.nextInt(4 - i1) == 0) {
|
|
|
|
l1 = random.nextInt(3);
|
|
|
|
this.setTypeAndData(world, i + Direction.a[Direction.f[k2]], j + l - 5 + i1, k + Direction.b[Direction.f[k2]], Blocks.COCOA, l1 << 2 | k2);
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-09 17:11:56 +01:00
|
|
|
}
|
2011-12-23 00:54:34 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2012-03-01 16:35:12 +01:00
|
|
|
// CraftBukkit - Changed world to BlockChangeDelegate
|
2013-11-04 14:07:38 +01:00
|
|
|
private void a(CraftBlockChangeDelegate world, int i, int j, int k, int l) {
|
|
|
|
this.setTypeAndData(world, i, j, k, Blocks.VINE, l);
|
2012-03-01 11:49:23 +01:00
|
|
|
int i1 = 4;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
--j;
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i, j, k).getMaterial() != Material.AIR || i1 <= 0) {
|
2012-03-01 11:49:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
this.setTypeAndData(world, i, j, k, Blocks.VINE, l);
|
2012-03-01 11:49:23 +01:00
|
|
|
--i1;
|
|
|
|
}
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|