2011-02-23 03:37:56 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2011-12-23 00:54:34 +01:00
|
|
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2012-03-16 07:32:25 +01:00
|
|
|
public class WorldGenTrees extends WorldGenerator 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) {
|
2012-07-29 09:33:13 +02:00
|
|
|
// CraftBukkit start - moved to generate
|
2011-12-23 00:54:34 +01:00
|
|
|
return this.generate((BlockChangeDelegate) world, random, i, j, k);
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
|
|
|
|
2011-12-23 00:54:34 +01:00
|
|
|
public boolean generate(BlockChangeDelegate 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) {
|
2011-11-20 09:01:14 +01:00
|
|
|
int i1;
|
2012-03-01 11:49:23 +01:00
|
|
|
byte b0;
|
2011-11-20 09:01:14 +01:00
|
|
|
int j1;
|
|
|
|
int k1;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
for (i1 = j; i1 <= j + 1 + l; ++i1) {
|
2012-03-01 11:49:23 +01:00
|
|
|
b0 = 1;
|
2011-11-20 09:01:14 +01:00
|
|
|
if (i1 == j) {
|
|
|
|
b0 = 0;
|
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (i1 >= j + 1 + l - 2) {
|
|
|
|
b0 = 2;
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
for (int l1 = i - b0; l1 <= i + b0 && flag; ++l1) {
|
|
|
|
for (j1 = k - b0; j1 <= k + b0 && flag; ++j1) {
|
|
|
|
if (i1 >= 0 && i1 < 256) {
|
|
|
|
k1 = world.getTypeId(l1, i1, j1);
|
|
|
|
if (k1 != 0 && k1 != Block.LEAVES.id && k1 != Block.GRASS.id && k1 != Block.DIRT.id && k1 != Block.LOG.id) {
|
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 {
|
|
|
|
i1 = world.getTypeId(i, j - 1, k);
|
2012-03-01 11:49:23 +01:00
|
|
|
if ((i1 == Block.GRASS.id || i1 == Block.DIRT.id) && j < 256 - l - 1) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.setType(world, i, j - 1, k, Block.DIRT.id);
|
2012-03-01 11:49:23 +01:00
|
|
|
b0 = 3;
|
|
|
|
byte b1 = 0;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
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
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
for (j1 = j - b0 + l; j1 <= j + l; ++j1) {
|
|
|
|
k1 = j1 - (j + l);
|
|
|
|
i2 = b1 + 1 - k1 / 2;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
for (j2 = i - i2; j2 <= i + i2; ++j2) {
|
|
|
|
k2 = j2 - i;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
for (int l2 = k - i2; l2 <= k + i2; ++l2) {
|
|
|
|
int i3 = l2 - k;
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (Math.abs(k2) != i2 || Math.abs(i3) != i2 || random.nextInt(2) != 0 && k1 != 0) {
|
|
|
|
int j3 = world.getTypeId(j2, j1, l2);
|
|
|
|
|
|
|
|
if (j3 == 0 || j3 == Block.LEAVES.id) {
|
|
|
|
this.setTypeAndData(world, j2, j1, l2, Block.LEAVES.id, this.d);
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
for (j1 = 0; j1 < l; ++j1) {
|
|
|
|
k1 = world.getTypeId(i, j + j1, k);
|
|
|
|
if (k1 == 0 || k1 == Block.LEAVES.id) {
|
|
|
|
this.setTypeAndData(world, i, j + j1, k, Block.LOG.id, this.c);
|
|
|
|
if (this.b && j1 > 0) {
|
2012-03-03 11:14:53 +01:00
|
|
|
if (random.nextInt(3) > 0 && world.isEmpty(i - 1, j + j1, k)) {
|
2012-03-01 11:49:23 +01:00
|
|
|
this.setTypeAndData(world, i - 1, j + j1, k, Block.VINE.id, 8);
|
|
|
|
}
|
|
|
|
|
2012-03-03 11:14:53 +01:00
|
|
|
if (random.nextInt(3) > 0 && world.isEmpty(i + 1, j + j1, k)) {
|
2012-03-01 11:49:23 +01:00
|
|
|
this.setTypeAndData(world, i + 1, j + j1, k, Block.VINE.id, 2);
|
|
|
|
}
|
|
|
|
|
2012-03-03 11:14:53 +01:00
|
|
|
if (random.nextInt(3) > 0 && world.isEmpty(i, j + j1, k - 1)) {
|
2012-03-01 11:49:23 +01:00
|
|
|
this.setTypeAndData(world, i, j + j1, k - 1, Block.VINE.id, 1);
|
|
|
|
}
|
|
|
|
|
2012-03-03 11:14:53 +01:00
|
|
|
if (random.nextInt(3) > 0 && world.isEmpty(i, j + j1, k + 1)) {
|
2012-03-01 11:49:23 +01:00
|
|
|
this.setTypeAndData(world, i, j + j1, k + 1, Block.VINE.id, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.b) {
|
|
|
|
for (j1 = j - 3 + l; j1 <= j + l; ++j1) {
|
|
|
|
k1 = j1 - (j + l);
|
|
|
|
i2 = 2 - k1 / 2;
|
|
|
|
|
|
|
|
for (j2 = i - i2; j2 <= i + i2; ++j2) {
|
|
|
|
for (k2 = k - i2; k2 <= k + i2; ++k2) {
|
|
|
|
if (world.getTypeId(j2, j1, k2) == Block.LEAVES.id) {
|
|
|
|
if (random.nextInt(4) == 0 && world.getTypeId(j2 - 1, j1, k2) == 0) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.b(world, j2 - 1, j1, k2, 8);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (random.nextInt(4) == 0 && world.getTypeId(j2 + 1, j1, k2) == 0) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.b(world, j2 + 1, j1, k2, 2);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (random.nextInt(4) == 0 && world.getTypeId(j2, j1, k2 - 1) == 0) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.b(world, j2, j1, k2 - 1, 1);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (random.nextInt(4) == 0 && world.getTypeId(j2, j1, k2 + 1) == 0) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.b(world, j2, j1, k2 + 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) {
|
|
|
|
for (j1 = 0; j1 < 2; ++j1) {
|
|
|
|
for (k1 = 0; k1 < 4; ++k1) {
|
|
|
|
if (random.nextInt(4 - j1) == 0) {
|
|
|
|
i2 = random.nextInt(3);
|
2012-10-25 05:53:23 +02:00
|
|
|
this.setTypeAndData(world, i + Direction.a[Direction.f[k1]], j + l - 5 + j1, k + Direction.b[Direction.f[k1]], Block.COCOA.id, i2 << 2 | k1);
|
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
|
2012-03-22 21:39:39 +01:00
|
|
|
private void b(BlockChangeDelegate world, int i, int j, int k, int l) {
|
|
|
|
this.setTypeAndData(world, i, j, k, Block.VINE.id, l);
|
2012-03-01 11:49:23 +01:00
|
|
|
int i1 = 4;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
--j;
|
|
|
|
if (world.getTypeId(i, j, k) != 0 || i1 <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-22 21:39:39 +01:00
|
|
|
this.setTypeAndData(world, i, j, k, Block.VINE.id, l);
|
2012-03-01 11:49:23 +01:00
|
|
|
--i1;
|
|
|
|
}
|
|
|
|
}
|
2011-02-23 03:37:56 +01:00
|
|
|
}
|