Implemented onStructureGrow event, thanks to md-5.

This commit is contained in:
Nathan Adams
2011-12-09 16:11:56 +00:00
parent 076460b419
commit 5e43c61fad
9 changed files with 323 additions and 56 deletions

View File

@@ -2,13 +2,23 @@ package net.minecraft.server;
import java.util.Random;
import org.bukkit.BlockChangeDelegate; // CraftBukkit
// CraftBukkit start
import org.bukkit.BlockChangeDelegate;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.world.StructureGrowEvent;
// Craftbukkit end
public class WorldGenBigTree extends WorldGenerator {
static final byte[] a = new byte[] { (byte) 2, (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 1};
Random b = new Random();
BlockChangeDelegate c; // CraftBukkit
// Craftbukkit start
BlockChangeDelegate c;
StructureGrowEvent event;
CraftWorld bukkitWorld;
// Craftbukkit end
int[] d = new int[] { 0, 0, 0};
int e = 0;
int f;
@@ -121,7 +131,15 @@ public class WorldGenBigTree extends WorldGenerator {
if (l1 != 0 && l1 != 18) {
++k1;
} else {
this.a(this.c, aint1[0], aint1[1], aint1[2], l, 0);
// Craftbukkit start
if (event == null) {
this.a(this.c, aint1[0], aint1[1], aint1[2], l, 0);
} else {
BlockState state = bukkitWorld.getBlockAt(aint1[0], aint1[1], aint1[2]).getState();
state.setTypeId(l);
event.getBlocks().add(state);
}
// Craftbukkit end
++k1;
}
}
@@ -197,7 +215,15 @@ public class WorldGenBigTree extends WorldGenerator {
aint3[b1] = MathHelper.floor((double) (aint[b1] + j) + 0.5D);
aint3[b2] = MathHelper.floor((double) aint[b2] + (double) j * d0 + 0.5D);
aint3[b3] = MathHelper.floor((double) aint[b3] + (double) j * d1 + 0.5D);
// Craftbukkit start
if (event == null) {
this.a(this.c, aint3[0], aint3[1], aint3[2], i, 0);
} else {
BlockState state = bukkitWorld.getBlockAt(aint3[0], aint3[1], aint3[2]).getState();
state.setTypeId(i);
event.getBlocks().add(state);
}
// Craftbukkit end
}
}
}
@@ -342,10 +368,12 @@ public class WorldGenBigTree extends WorldGenerator {
// 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);
return this.generate((BlockChangeDelegate) world, random, i, j, k, null, null, world.getWorld());
}
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) {
this.event = event;
this.bukkitWorld = bukkitWorld;
// CraftBukkit end
this.c = world;
long l = random.nextLong();
@@ -365,6 +393,20 @@ public class WorldGenBigTree extends WorldGenerator {
this.b();
this.c();
this.d();
// Craftbukkit start
if (event != null) {
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
world.setRawTypeId(i, j, k, 0);
for (BlockState state : event.getBlocks()) {
state.update();
}
if (event.isFromBonemeal() && itemstack != null) {
--itemstack.count;
}
}
}
// Craftbukkit end
return true;
}
}