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

216 Zeilen
8.1 KiB
Java

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;
import org.bukkit.block.BlockState;
import org.bukkit.material.MaterialData;
2012-01-12 12:02:39 +01:00
// CraftBukkit end
public class WorldGenHugeMushroom extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit - add interface
private int a = -1;
public WorldGenHugeMushroom(int i) {
2012-03-01 11:49:23 +01:00
super(true);
this.a = i;
}
2012-03-01 11:49:23 +01:00
public WorldGenHugeMushroom() {
super(false);
}
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);
}
2013-11-04 14:07:38 +01:00
public boolean generate(CraftBlockChangeDelegate world, Random random, int i, int j, int k) {
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) {
// CraftBukkit end
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) {
int j1;
int k1;
2013-11-04 14:07:38 +01:00
for (int l1 = j; l1 <= j + 1 + i1; ++l1) {
byte b0 = 3;
2013-11-04 14:07:38 +01:00
if (l1 <= j + 3) {
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) {
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) {
return false;
} else {
2012-01-12 12:02:39 +01:00
// CraftBukkit start
if (event == null) {
2013-11-04 14:07:38 +01:00
this.setTypeAndData(world, i, j - 1, k, Blocks.DIRT, 0);
} else {
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
2013-11-04 14:07:38 +01:00
dirtState.setTypeId(Block.b(Blocks.DIRT));
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;
if (l == 1) {
2013-11-04 14:07:38 +01:00
i2 = j + i1 - 3;
}
2013-11-04 14:07:38 +01:00
for (j1 = i2; j1 <= j + i1; ++j1) {
k1 = 1;
if (j1 < j + i1) {
++k1;
}
if (l == 0) {
2013-11-04 14:07:38 +01:00
k1 = 3;
}
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) {
int l2 = 5;
2013-11-04 14:07:38 +01:00
if (j2 == i - k1) {
--l2;
}
2013-11-04 14:07:38 +01:00
if (j2 == i + k1) {
++l2;
}
2013-11-04 14:07:38 +01:00
if (k2 == k - k1) {
l2 -= 3;
}
2013-11-04 14:07:38 +01:00
if (k2 == k + k1) {
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)) {
continue;
}
2013-11-04 14:07:38 +01:00
if (j2 == i - (k1 - 1) && k2 == k - k1) {
l2 = 1;
}
2013-11-04 14:07:38 +01:00
if (j2 == i - k1 && k2 == k - (k1 - 1)) {
l2 = 1;
}
2013-11-04 14:07:38 +01:00
if (j2 == i + (k1 - 1) && k2 == k - k1) {
l2 = 3;
}
2013-11-04 14:07:38 +01:00
if (j2 == i + k1 && k2 == k - (k1 - 1)) {
l2 = 3;
}
2013-11-04 14:07:38 +01:00
if (j2 == i - (k1 - 1) && k2 == k + k1) {
l2 = 7;
}
2013-11-04 14:07:38 +01:00
if (j2 == i - k1 && k2 == k + (k1 - 1)) {
l2 = 7;
}
2013-11-04 14:07:38 +01:00
if (j2 == i + (k1 - 1) && k2 == k + k1) {
l2 = 9;
}
2013-11-04 14:07:38 +01:00
if (j2 == i + k1 && k2 == k + (k1 - 1)) {
l2 = 9;
}
}
2013-11-04 14:07:38 +01:00
if (l2 == 5 && j1 < j + i1) {
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
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);
} 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));
event.getBlocks().add(state);
}
2012-01-12 12:02:39 +01:00
// CraftBukkit end
}
}
}
}
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
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);
} 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));
event.getBlocks().add(state);
}
2012-01-12 12:02:39 +01:00
// CraftBukkit end
}
}
2012-01-12 12:02:39 +01:00
// CraftBukkit start
if (event != null) {
org.bukkit.Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
for (BlockState state : event.getBlocks()) {
state.update(true);
}
}
}
2012-01-12 12:02:39 +01:00
// CraftBukkit end
return true;
}
}
} else {
return false;
}
}
}