2011-01-30 22:53:57 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2011-12-23 00:54:34 +01:00
|
|
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2012-03-16 07:32:25 +01:00
|
|
|
public class WorldGenForest extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public WorldGenForest(boolean flag) {
|
|
|
|
super(flag);
|
|
|
|
}
|
2011-01-30 22:53:57 +01:00
|
|
|
|
|
|
|
public boolean a(World world, Random random, int i, int j, int k) {
|
|
|
|
// CraftBukkit start
|
|
|
|
// sk: The idea is to have (our) WorldServer implement
|
|
|
|
// BlockChangeDelegate and then we can implicitly cast World to
|
|
|
|
// WorldServer (a safe cast, AFAIK) and no code will be broken. This
|
|
|
|
// then allows plugins to catch manually-invoked generation events
|
2011-12-23 00:54:34 +01:00
|
|
|
return this.generate((BlockChangeDelegate) world, random, i, j, k);
|
2011-01-30 22:53:57 +01:00
|
|
|
}
|
2011-02-02 00:32:18 +01:00
|
|
|
|
2011-12-23 00:54:34 +01:00
|
|
|
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
|
2011-01-30 22:53:57 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
int l = random.nextInt(3) + 5;
|
|
|
|
boolean flag = true;
|
|
|
|
|
2012-03-02 20:31:06 +01:00
|
|
|
if (j >= 1 && j + l + 1 <= 256) {
|
2011-11-20 09:01:14 +01:00
|
|
|
int i1;
|
|
|
|
int j1;
|
|
|
|
int k1;
|
|
|
|
int l1;
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
for (i1 = j; i1 <= j + 1 + l; ++i1) {
|
|
|
|
byte b0 = 1;
|
2011-01-30 22:53:57 +01:00
|
|
|
|
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-01-30 22:53:57 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
for (j1 = i - b0; j1 <= i + b0 && flag; ++j1) {
|
|
|
|
for (k1 = k - b0; k1 <= k + b0 && flag; ++k1) {
|
2012-03-02 20:31:06 +01:00
|
|
|
if (i1 >= 0 && i1 < 256) {
|
2011-11-20 09:01:14 +01:00
|
|
|
l1 = world.getTypeId(j1, i1, k1);
|
|
|
|
if (l1 != 0 && l1 != Block.LEAVES.id) {
|
|
|
|
flag = false;
|
2011-01-30 22:53:57 +01:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
} else {
|
2011-01-30 22:53:57 +01:00
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (!flag) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
i1 = world.getTypeId(i, j - 1, k);
|
2012-03-02 20:31:06 +01:00
|
|
|
if ((i1 == Block.GRASS.id || i1 == Block.DIRT.id) && j < 256 - l - 1) {
|
2012-03-21 22:01:11 +01:00
|
|
|
this.setTypeAndData(world, i, j - 1, k, Block.DIRT.id, 0); // CraftBukkit
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
int i2;
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
for (i2 = j - 3 + l; i2 <= j + l; ++i2) {
|
|
|
|
j1 = i2 - (j + l);
|
|
|
|
k1 = 1 - j1 / 2;
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
for (l1 = i - k1; l1 <= i + k1; ++l1) {
|
|
|
|
int j2 = l1 - i;
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
for (int k2 = k - k1; k2 <= k + k1; ++k2) {
|
|
|
|
int l2 = k2 - k;
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if ((Math.abs(j2) != k1 || Math.abs(l2) != k1 || random.nextInt(2) != 0 && j1 != 0) && !Block.n[world.getTypeId(l1, i2, k2)]) {
|
2011-12-23 00:54:34 +01:00
|
|
|
this.setTypeAndData(world, l1, i2, k2, Block.LEAVES.id, 2);
|
2011-01-30 22:53:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-01-30 22:53:57 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
for (i2 = 0; i2 < l; ++i2) {
|
|
|
|
j1 = world.getTypeId(i, j + i2, k);
|
|
|
|
if (j1 == 0 || j1 == Block.LEAVES.id) {
|
2011-12-23 00:54:34 +01:00
|
|
|
this.setTypeAndData(world, i, j + i2, k, Block.LOG.id, 2);
|
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-01-30 22:53:57 +01:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
2011-01-30 22:53:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|