Paper/src/main/java/net/minecraft/server/WorldGenTrees.java

178 Zeilen
6.9 KiB
Java

2011-02-23 03:37:56 +01:00
package net.minecraft.server;
import java.util.Random;
import org.bukkit.BlockChangeDelegate; // CraftBukkit
2011-02-23 03:37:56 +01:00
public class WorldGenTrees extends WorldGenerator {
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) {
// 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
return this.generate((BlockChangeDelegate) world, random, i, j, k);
2011-02-23 03:37:56 +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) {
world.setRawTypeId(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
2012-03-01 11:49:23 +01:00
if ((Math.abs(k2) != i2 || Math.abs(i3) != i2 || random.nextInt(2) != 0 && k1 != 0) && !Block.n[world.getTypeId(j2, j1, l2)]) {
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) {
if (random.nextInt(3) > 0 && ((World )world).isEmpty(i - 1, j + j1, k)) { // Craftbukkit cast to World
this.setTypeAndData(world, i - 1, j + j1, k, Block.VINE.id, 8);
}
if (random.nextInt(3) > 0 && ((World )world).isEmpty(i + 1, j + j1, k)) { // Craftbukkit cast to World
this.setTypeAndData(world, i + 1, j + j1, k, Block.VINE.id, 2);
}
if (random.nextInt(3) > 0 && ((World )world).isEmpty(i, j + j1, k - 1)) { // Craftbukkit cast to World
this.setTypeAndData(world, i, j + j1, k - 1, Block.VINE.id, 1);
}
if (random.nextInt(3) > 0 && ((World )world).isEmpty(i, j + j1, k + 1)) { // Craftbukkit cast to World
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) {
this.a((World) world, j2 - 1, j1, k2, 8); // Craftbukkit cast to World
}
if (random.nextInt(4) == 0 && world.getTypeId(j2 + 1, j1, k2) == 0) {
this.a((World) world, j2 + 1, j1, k2, 2); // Craftbukkit cast to World
}
if (random.nextInt(4) == 0 && world.getTypeId(j2, j1, k2 - 1) == 0) {
this.a((World) world, j2, j1, k2 - 1, 1); // Craftbukkit cast to World
}
if (random.nextInt(4) == 0 && world.getTypeId(j2, j1, k2 + 1) == 0) {
this.a((World) world, j2, j1, k2 + 1, 4); // Craftbukkit cast to World
}
}
}
}
}
}
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
private void a(World world, int i, int j, int k, int l) {
world.setTypeIdAndData(i, j, k, Block.VINE.id, l);
int i1 = 4;
while (true) {
--j;
if (world.getTypeId(i, j, k) != 0 || i1 <= 0) {
return;
}
world.setTypeIdAndData(i, j, k, Block.VINE.id, l);
--i1;
}
}
2011-02-23 03:37:56 +01:00
}