diff options
author | Nathan Adams <dinnerbone@dinnerbone.com> | 2011-12-09 16:11:56 +0000 |
---|---|---|
committer | Nathan Adams <dinnerbone@dinnerbone.com> | 2011-12-09 16:11:56 +0000 |
commit | 5e43c61fad9c6620b20518b120ac0448387f2ee5 (patch) | |
tree | e35d5a57a4a52f463737f503540c80c31e89c263 /src/main/java/net/minecraft/server/WorldGenTrees.java | |
parent | 076460b419586ff5a79e68b700eb6a0ab1aa5994 (diff) | |
download | craftbukkit-5e43c61fad9c6620b20518b120ac0448387f2ee5.tar craftbukkit-5e43c61fad9c6620b20518b120ac0448387f2ee5.tar.gz craftbukkit-5e43c61fad9c6620b20518b120ac0448387f2ee5.tar.lz craftbukkit-5e43c61fad9c6620b20518b120ac0448387f2ee5.tar.xz craftbukkit-5e43c61fad9c6620b20518b120ac0448387f2ee5.zip |
Implemented onStructureGrow event, thanks to md-5.
Diffstat (limited to 'src/main/java/net/minecraft/server/WorldGenTrees.java')
-rw-r--r-- | src/main/java/net/minecraft/server/WorldGenTrees.java | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/src/main/java/net/minecraft/server/WorldGenTrees.java b/src/main/java/net/minecraft/server/WorldGenTrees.java index 15450e41..c9c81b64 100644 --- a/src/main/java/net/minecraft/server/WorldGenTrees.java +++ b/src/main/java/net/minecraft/server/WorldGenTrees.java @@ -2,7 +2,13 @@ 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 WorldGenTrees extends WorldGenerator { @@ -16,10 +22,10 @@ public class WorldGenTrees 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) { // CraftBukkit end int l = random.nextInt(3) + 4; boolean flag = true; @@ -60,7 +66,15 @@ public class WorldGenTrees extends WorldGenerator { } else { i1 = world.getTypeId(i, j - 1, k); if ((i1 == Block.GRASS.id || i1 == Block.DIRT.id) && j < world.getHeight() - l - 1) { // CraftBukkit - world.setRawTypeId(i, j - 1, k, Block.DIRT.id); + // Craftbukkit start + if (event == null) { + world.setRawTypeId(i, j - 1, k, Block.DIRT.id); + } else { + BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState(); + dirtState.setTypeId(Block.DIRT.id); + event.getBlocks().add(dirtState); + } + // Craftbukkit end int i2; @@ -75,7 +89,15 @@ public class WorldGenTrees extends WorldGenerator { int l2 = k2 - k; if ((Math.abs(j2) != k1 || Math.abs(l2) != k1 || random.nextInt(2) != 0 && j1 != 0) && !Block.o[world.getTypeId(l1, i2, k2)]) { - this.a(world, l1, i2, k2, Block.LEAVES.id, 0); + // Craftbukkit start + if (event == null) { + this.a(world, l1, i2, k2, Block.LEAVES.id, 0); + } else { + BlockState leavesState = bukkitWorld.getBlockAt(l1, i2, k2).getState(); + leavesState.setTypeId(Block.LEAVES.id); + event.getBlocks().add(leavesState); + } + // Craftbukkit end } } } @@ -84,10 +106,30 @@ public class WorldGenTrees extends WorldGenerator { for (i2 = 0; i2 < l; ++i2) { j1 = world.getTypeId(i, j + i2, k); if (j1 == 0 || j1 == Block.LEAVES.id) { - this.a(world, i, j + i2, k, Block.LOG.id, 0); + // Craftbukkit start + if (event == null) { + this.a(world, i, j + i2, k, Block.LOG.id, 0); + } else { + BlockState logState = bukkitWorld.getBlockAt(i, j + i2, k).getState(); + logState.setTypeId(Block.LOG.id); + event.getBlocks().add(logState); + } + // Craftbukkit end } } - + // Craftbukkit start + if (event != null) { + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + for (BlockState state : event.getBlocks()) { + state.update(true); + } + if (event.isFromBonemeal() && itemstack != null) { + --itemstack.count; + } + } + } + // Craftbukkit end return true; } else { return false; |