2011-12-09 17:01:37 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2012-03-14 03:38:39 +01:00
|
|
|
import org.bukkit.BlockChangeDelegate;
|
2011-12-09 17:11:56 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.material.MaterialData;
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2011-12-09 17:01:37 +01:00
|
|
|
|
2012-03-14 03:38:39 +01:00
|
|
|
public class WorldGenHugeMushroom extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit - add interface
|
2011-12-09 17:01:37 +01:00
|
|
|
|
|
|
|
private int a = -1;
|
|
|
|
|
|
|
|
public WorldGenHugeMushroom(int i) {
|
2012-03-01 11:49:23 +01:00
|
|
|
super(true);
|
2011-12-09 17:01:37 +01:00
|
|
|
this.a = i;
|
|
|
|
}
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
public WorldGenHugeMushroom() {
|
|
|
|
super(false);
|
|
|
|
}
|
2011-12-09 17:01:37 +01:00
|
|
|
|
2012-03-14 03:38:39 +01:00
|
|
|
// CraftBukkit start - delegate to generate() and use BlockChangeDelegate
|
2011-12-09 17:01:37 +01:00
|
|
|
public boolean a(World world, Random random, int i, int j, int k) {
|
2012-03-14 03:38:39 +01:00
|
|
|
return grow((BlockChangeDelegate) world, random, i, j, k, null, null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
|
2011-12-09 17:11:56 +01:00
|
|
|
return grow(world, random, i, j, k, null, null, null);
|
|
|
|
}
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
public boolean grow(BlockChangeDelegate world, Random random, int i, int j, int k, org.bukkit.event.world.StructureGrowEvent event, ItemStack itemstack, org.bukkit.craftbukkit.CraftWorld bukkitWorld) {
|
2011-12-09 17:11:56 +01:00
|
|
|
// CraftBukkit end
|
2011-12-09 17:01:37 +01:00
|
|
|
int l = random.nextInt(2);
|
|
|
|
|
|
|
|
if (this.a >= 0) {
|
|
|
|
l = this.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i1 = random.nextInt(3) + 4;
|
|
|
|
boolean flag = true;
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if (j >= 1 && j + i1 + 1 < 256) {
|
2011-12-09 17:01:37 +01:00
|
|
|
int j1;
|
|
|
|
int k1;
|
|
|
|
int l1;
|
|
|
|
int i2;
|
|
|
|
|
|
|
|
for (j1 = j; j1 <= j + 1 + i1; ++j1) {
|
|
|
|
byte b0 = 3;
|
|
|
|
|
|
|
|
if (j1 == j) {
|
|
|
|
b0 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (k1 = i - b0; k1 <= i + b0 && flag; ++k1) {
|
|
|
|
for (l1 = k - b0; l1 <= k + b0 && flag; ++l1) {
|
2012-03-01 11:49:23 +01:00
|
|
|
if (j1 >= 0 && j1 < 256) {
|
2011-12-09 17:01:37 +01:00
|
|
|
i2 = world.getTypeId(k1, j1, l1);
|
|
|
|
if (i2 != 0 && i2 != Block.LEAVES.id) {
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
j1 = world.getTypeId(i, j - 1, k);
|
|
|
|
if (j1 != Block.DIRT.id && j1 != Block.GRASS.id && j1 != Block.MYCEL.id) {
|
|
|
|
return false;
|
2012-03-14 03:38:39 +01:00
|
|
|
// CraftBukkit - Adjust canPlace check to handle non-World BlockChangeDelegates (orig check was: !Block.BROWN_MUSHROOM.canPlace(world, i, j, k))
|
|
|
|
} else if ((world.getTypeId(i, j, k) != 0 && !Block.byId[world.getTypeId(i, j, k)].material.isReplacable()) || (world instanceof World && !Block.BROWN_MUSHROOM.canPlace((World) world, i, j, k))) {
|
2011-12-09 17:01:37 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2011-12-09 17:11:56 +01:00
|
|
|
if (event == null) {
|
2012-03-14 03:38:39 +01:00
|
|
|
this.setTypeAndData(world, i, j - 1, k, Block.DIRT.id, 0);
|
2011-12-09 17:11:56 +01:00
|
|
|
} else {
|
|
|
|
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
|
|
|
|
dirtState.setTypeId(Block.DIRT.id);
|
|
|
|
event.getBlocks().add(dirtState);
|
|
|
|
}
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2011-12-09 17:01:37 +01:00
|
|
|
int j2 = j + i1;
|
|
|
|
|
|
|
|
if (l == 1) {
|
|
|
|
j2 = j + i1 - 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (k1 = j2; k1 <= j + i1; ++k1) {
|
|
|
|
l1 = 1;
|
|
|
|
if (k1 < j + i1) {
|
|
|
|
++l1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l == 0) {
|
|
|
|
l1 = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i2 = i - l1; i2 <= i + l1; ++i2) {
|
|
|
|
for (int k2 = k - l1; k2 <= k + l1; ++k2) {
|
|
|
|
int l2 = 5;
|
|
|
|
|
|
|
|
if (i2 == i - l1) {
|
|
|
|
--l2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i + l1) {
|
|
|
|
++l2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k2 == k - l1) {
|
|
|
|
l2 -= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k2 == k + l1) {
|
|
|
|
l2 += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l == 0 || k1 < j + i1) {
|
|
|
|
if ((i2 == i - l1 || i2 == i + l1) && (k2 == k - l1 || k2 == k + l1)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i - (l1 - 1) && k2 == k - l1) {
|
|
|
|
l2 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i - l1 && k2 == k - (l1 - 1)) {
|
|
|
|
l2 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i + (l1 - 1) && k2 == k - l1) {
|
|
|
|
l2 = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i + l1 && k2 == k - (l1 - 1)) {
|
|
|
|
l2 = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i - (l1 - 1) && k2 == k + l1) {
|
|
|
|
l2 = 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i - l1 && k2 == k + (l1 - 1)) {
|
|
|
|
l2 = 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i + (l1 - 1) && k2 == k + l1) {
|
|
|
|
l2 = 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2 == i + l1 && k2 == k + (l1 - 1)) {
|
|
|
|
l2 = 9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l2 == 5 && k1 < j + i1) {
|
|
|
|
l2 = 0;
|
|
|
|
}
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if ((l2 != 0 || j >= j + i1 - 1) && !Block.n[world.getTypeId(i2, k1, k2)]) {
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2011-12-09 17:11:56 +01:00
|
|
|
if (event == null) {
|
2012-03-14 03:38:39 +01:00
|
|
|
this.setTypeAndData(world, i2, k1, k2, Block.BIG_MUSHROOM_1.id + l, l2);
|
2011-12-09 17:11:56 +01:00
|
|
|
} else {
|
|
|
|
BlockState state = bukkitWorld.getBlockAt(i2, k1, k2).getState();
|
|
|
|
state.setTypeId(Block.BIG_MUSHROOM_1.id + l);
|
|
|
|
state.setData(new MaterialData(Block.BIG_MUSHROOM_1.id + l, (byte) l2));
|
|
|
|
event.getBlocks().add(state);
|
|
|
|
}
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2011-12-09 17:01:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (k1 = 0; k1 < i1; ++k1) {
|
|
|
|
l1 = world.getTypeId(i, j + k1, k);
|
2012-03-01 11:49:23 +01:00
|
|
|
if (!Block.n[l1]) {
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2011-12-09 17:11:56 +01:00
|
|
|
if (event == null) {
|
2012-03-14 03:38:39 +01:00
|
|
|
this.setTypeAndData(world, i, j + k1, k, Block.BIG_MUSHROOM_1.id + l, 10);
|
2011-12-09 17:11:56 +01:00
|
|
|
} else {
|
|
|
|
BlockState state = bukkitWorld.getBlockAt(i, j + k1, k).getState();
|
|
|
|
state.setTypeId(Block.BIG_MUSHROOM_1.id + l);
|
|
|
|
state.setData(new MaterialData(Block.BIG_MUSHROOM_1.id + l, (byte) 10));
|
|
|
|
event.getBlocks().add(state);
|
|
|
|
}
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2011-12-09 17:01:37 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2011-12-09 17:11:56 +01:00
|
|
|
if (event != null) {
|
2012-07-22 08:18:00 +02:00
|
|
|
org.bukkit.Bukkit.getPluginManager().callEvent(event);
|
2011-12-09 17:11:56 +01:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
for (BlockState state : event.getBlocks()) {
|
|
|
|
state.update(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2011-12-09 17:01:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|