2011-12-09 17:01:37 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2013-11-04 14:07:38 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftBlockChangeDelegate;
|
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
|
|
|
|
|
|
|
public boolean a(World world, Random random, int i, int j, int k) {
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Moved to generate
|
2013-11-04 14:07:38 +01:00
|
|
|
return grow(new CraftBlockChangeDelegate((org.bukkit.BlockChangeDelegate) world), random, i, j, k, null, null, null);
|
2012-03-14 03:38:39 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean generate(CraftBlockChangeDelegate 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);
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean grow(CraftBlockChangeDelegate 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;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int l1 = j; l1 <= j + 1 + i1; ++l1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
byte b0 = 3;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (l1 <= j + 3) {
|
2011-12-09 17:01:37 +01:00
|
|
|
b0 = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (j1 = i - b0; j1 <= i + b0 && flag; ++j1) {
|
|
|
|
for (k1 = k - b0; k1 <= k + b0 && flag; ++k1) {
|
|
|
|
if (l1 >= 0 && l1 < 256) {
|
|
|
|
Block block = world.getType(j1, l1, k1);
|
|
|
|
|
|
|
|
if (block.getMaterial() != Material.AIR && block.getMaterial() != Material.LEAVES) {
|
2011-12-09 17:01:37 +01:00
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
Block block1 = world.getType(i, j - 1, k);
|
|
|
|
|
|
|
|
if (block1 != Blocks.DIRT && block1 != Blocks.GRASS && block1 != Blocks.MYCEL) {
|
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) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.setTypeAndData(world, i, j - 1, k, Blocks.DIRT, 0);
|
2011-12-09 17:11:56 +01:00
|
|
|
} else {
|
|
|
|
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
|
2013-11-04 14:07:38 +01:00
|
|
|
dirtState.setTypeId(Block.b(Blocks.DIRT));
|
2011-12-09 17:11:56 +01:00
|
|
|
event.getBlocks().add(dirtState);
|
|
|
|
}
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2013-11-04 14:07:38 +01:00
|
|
|
|
|
|
|
int i2 = j + i1;
|
2011-12-09 17:01:37 +01:00
|
|
|
|
|
|
|
if (l == 1) {
|
2013-11-04 14:07:38 +01:00
|
|
|
i2 = j + i1 - 3;
|
2011-12-09 17:01:37 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (j1 = i2; j1 <= j + i1; ++j1) {
|
|
|
|
k1 = 1;
|
|
|
|
if (j1 < j + i1) {
|
|
|
|
++k1;
|
2011-12-09 17:01:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (l == 0) {
|
2013-11-04 14:07:38 +01:00
|
|
|
k1 = 3;
|
2011-12-09 17:01:37 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (int j2 = i - k1; j2 <= i + k1; ++j2) {
|
|
|
|
for (int k2 = k - k1; k2 <= k + k1; ++k2) {
|
2011-12-09 17:01:37 +01:00
|
|
|
int l2 = 5;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i - k1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
--l2;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i + k1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
++l2;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (k2 == k - k1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 -= 3;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (k2 == k + k1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 += 3;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (l == 0 || j1 < j + i1) {
|
|
|
|
if ((j2 == i - k1 || j2 == i + k1) && (k2 == k - k1 || k2 == k + k1)) {
|
2011-12-09 17:01:37 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i - (k1 - 1) && k2 == k - k1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 1;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i - k1 && k2 == k - (k1 - 1)) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 1;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i + (k1 - 1) && k2 == k - k1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 3;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i + k1 && k2 == k - (k1 - 1)) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 3;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i - (k1 - 1) && k2 == k + k1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 7;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i - k1 && k2 == k + (k1 - 1)) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 7;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i + (k1 - 1) && k2 == k + k1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 9;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (j2 == i + k1 && k2 == k + (k1 - 1)) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (l2 == 5 && j1 < j + i1) {
|
2011-12-09 17:01:37 +01:00
|
|
|
l2 = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if ((l2 != 0 || j >= j + i1 - 1) && !world.getType(j2, j1, k2).j()) {
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2011-12-09 17:11:56 +01:00
|
|
|
if (event == null) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.setTypeAndData(world, j2, j1, k2, Block.e(Block.b(Blocks.BIG_MUSHROOM_1) + l), l2);
|
2011-12-09 17:11:56 +01:00
|
|
|
} else {
|
|
|
|
BlockState state = bukkitWorld.getBlockAt(i2, k1, k2).getState();
|
2013-11-04 14:07:38 +01:00
|
|
|
state.setTypeId(Block.b(Blocks.BIG_MUSHROOM_1) + l);
|
|
|
|
state.setData(new MaterialData(Block.b(Blocks.BIG_MUSHROOM_1) + l, (byte) l2));
|
2011-12-09 17:11:56 +01:00
|
|
|
event.getBlocks().add(state);
|
|
|
|
}
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2011-12-09 17:01:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
for (j1 = 0; j1 < i1; ++j1) {
|
|
|
|
Block block2 = world.getType(i, j + j1, k);
|
|
|
|
|
|
|
|
if (!block2.j()) {
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2011-12-09 17:11:56 +01:00
|
|
|
if (event == null) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.setTypeAndData(world, i, j + j1, k, Block.e(Block.b(Blocks.BIG_MUSHROOM_1) + l), 10);
|
2011-12-09 17:11:56 +01:00
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
BlockState state = bukkitWorld.getBlockAt(i, j + j1, k).getState();
|
|
|
|
state.setTypeId(Block.b(Blocks.BIG_MUSHROOM_1) + l);
|
|
|
|
state.setData(new MaterialData(Block.b(Blocks.BIG_MUSHROOM_1) + l, (byte) 10));
|
2011-12-09 17:11:56 +01:00
|
|
|
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
|
2011-12-09 17:01:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|