2012-03-12 01:41:49 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public class WorldGenSwampTree extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface
|
2012-03-12 01:41:49 +01:00
|
|
|
|
|
|
|
public WorldGenSwampTree() {}
|
|
|
|
|
|
|
|
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
|
|
|
|
return this.generate((BlockChangeDelegate) world, random, i, j, k);
|
2012-03-14 03:38:39 +01:00
|
|
|
}
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
|
|
|
|
// CraftBukkit end
|
2012-03-12 01:41:49 +01:00
|
|
|
int l;
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
for (l = random.nextInt(4) + 5; world.getTypeId(i, j - 1, k) != 0 && Block.byId[world.getTypeId(i, j - 1, k)].material == Material.WATER; --j) { // CraftBukkit - bypass world.getMaterial
|
2012-03-12 01:41:49 +01:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean flag = true;
|
|
|
|
|
|
|
|
if (j >= 1 && j + l + 1 <= 128) {
|
|
|
|
int i1;
|
|
|
|
int j1;
|
|
|
|
int k1;
|
|
|
|
int l1;
|
|
|
|
|
|
|
|
for (i1 = j; i1 <= j + 1 + l; ++i1) {
|
|
|
|
byte b0 = 1;
|
|
|
|
|
|
|
|
if (i1 == j) {
|
|
|
|
b0 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i1 >= j + 1 + l - 2) {
|
|
|
|
b0 = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j1 = i - b0; j1 <= i + b0 && flag; ++j1) {
|
|
|
|
for (k1 = k - b0; k1 <= k + b0 && flag; ++k1) {
|
|
|
|
if (i1 >= 0 && i1 < 128) {
|
|
|
|
l1 = world.getTypeId(j1, i1, k1);
|
|
|
|
if (l1 != 0 && l1 != Block.LEAVES.id) {
|
|
|
|
if (l1 != Block.STATIONARY_WATER.id && l1 != Block.WATER.id) {
|
|
|
|
flag = false;
|
|
|
|
} else if (i1 > j) {
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
i1 = world.getTypeId(i, j - 1, k);
|
|
|
|
if ((i1 == Block.GRASS.id || i1 == Block.DIRT.id) && j < 128 - l - 1) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.setType(world, i, j - 1, k, Block.DIRT.id);
|
2012-03-12 01:41:49 +01:00
|
|
|
|
|
|
|
int i2;
|
|
|
|
int j2;
|
|
|
|
|
|
|
|
for (j2 = j - 3 + l; j2 <= j + l; ++j2) {
|
|
|
|
j1 = j2 - (j + l);
|
|
|
|
k1 = 2 - j1 / 2;
|
|
|
|
|
|
|
|
for (l1 = i - k1; l1 <= i + k1; ++l1) {
|
|
|
|
i2 = l1 - i;
|
|
|
|
|
|
|
|
for (int k2 = k - k1; k2 <= k + k1; ++k2) {
|
|
|
|
int l2 = k2 - k;
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if ((Math.abs(i2) != k1 || Math.abs(l2) != k1 || random.nextInt(2) != 0 && j1 != 0) && !Block.q[world.getTypeId(l1, j2, k2)]) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.setType(world, l1, j2, k2, Block.LEAVES.id);
|
2012-03-12 01:41:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j2 = 0; j2 < l; ++j2) {
|
|
|
|
j1 = world.getTypeId(i, j + j2, k);
|
|
|
|
if (j1 == 0 || j1 == Block.LEAVES.id || j1 == Block.WATER.id || j1 == Block.STATIONARY_WATER.id) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.setType(world, i, j + j2, k, Block.LOG.id);
|
2012-03-12 01:41:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j2 = j - 3 + l; j2 <= j + l; ++j2) {
|
|
|
|
j1 = j2 - (j + l);
|
|
|
|
k1 = 2 - j1 / 2;
|
|
|
|
|
|
|
|
for (l1 = i - k1; l1 <= i + k1; ++l1) {
|
|
|
|
for (i2 = k - k1; i2 <= k + k1; ++i2) {
|
|
|
|
if (world.getTypeId(l1, j2, i2) == Block.LEAVES.id) {
|
|
|
|
if (random.nextInt(4) == 0 && world.getTypeId(l1 - 1, j2, i2) == 0) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.b(world, l1 - 1, j2, i2, 8);
|
2012-03-12 01:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (random.nextInt(4) == 0 && world.getTypeId(l1 + 1, j2, i2) == 0) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.b(world, l1 + 1, j2, i2, 2);
|
2012-03-12 01:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (random.nextInt(4) == 0 && world.getTypeId(l1, j2, i2 - 1) == 0) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.b(world, l1, j2, i2 - 1, 1);
|
2012-03-12 01:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (random.nextInt(4) == 0 && world.getTypeId(l1, j2, i2 + 1) == 0) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.b(world, l1, j2, i2 + 1, 4);
|
2012-03-12 01:41:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 21:39:39 +01:00
|
|
|
// CraftBukkit - change signature
|
2012-07-22 08:18:00 +02:00
|
|
|
private void b(BlockChangeDelegate world, int i, int j, int k, int l) {
|
2012-03-22 21:39:39 +01:00
|
|
|
this.setTypeAndData(world, i, j, k, Block.VINE.id, l);
|
2012-03-12 01:41:49 +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-12 01:41:49 +01:00
|
|
|
--i1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|