diff --git a/src/main/java/net/minecraft/server/BlockMushroom.java b/src/main/java/net/minecraft/server/BlockMushroom.java index 37bfe15840..3c6e662eb4 100644 --- a/src/main/java/net/minecraft/server/BlockMushroom.java +++ b/src/main/java/net/minecraft/server/BlockMushroom.java @@ -1,7 +1,15 @@ package net.minecraft.server; +import java.util.ArrayList; import java.util.Random; +// Craftbukkit start +import org.bukkit.Location; +import org.bukkit.TreeType; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.world.StructureGrowEvent; +// Craftbukkit end public class BlockMushroom extends BlockFlower { @@ -82,23 +90,32 @@ public class BlockMushroom extends BlockFlower { } } - public boolean b(World world, int i, int j, int k, Random random) { + // CraftBukkit - added bonemeal, player and itemstack + public boolean b(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) { int l = world.getData(i, j, k); world.setRawTypeId(i, j, k, 0); + // CraftBukkit start + boolean grown = false; + StructureGrowEvent event = null; + Location location = new Location(world.getWorld(), i, j, k); WorldGenHugeMushroom worldgenhugemushroom = null; if (this.id == Block.BROWN_MUSHROOM.id) { + event = new StructureGrowEvent(location, TreeType.BROWN_MUSHROOM, bonemeal, player, new ArrayList()); worldgenhugemushroom = new WorldGenHugeMushroom(0); } else if (this.id == Block.RED_MUSHROOM.id) { + event = new StructureGrowEvent(location, TreeType.RED_MUSHROOM, bonemeal, player, new ArrayList()); worldgenhugemushroom = new WorldGenHugeMushroom(1); } - - if (worldgenhugemushroom != null && worldgenhugemushroom.a(world, random, i, j, k)) { - return true; - } else { + if (worldgenhugemushroom != null && event != null){ + grown = worldgenhugemushroom.grow(world, random, i, j, k, event, itemstack, world.getWorld()); + } + if (!grown || event.isCancelled()){ world.setRawTypeIdAndData(i, j, k, this.id, l); return false; } + return true; + // CraftBukkit end } } diff --git a/src/main/java/net/minecraft/server/BlockSapling.java b/src/main/java/net/minecraft/server/BlockSapling.java index 521810cb45..db1a3caa11 100644 --- a/src/main/java/net/minecraft/server/BlockSapling.java +++ b/src/main/java/net/minecraft/server/BlockSapling.java @@ -1,8 +1,15 @@ package net.minecraft.server; +import java.util.ArrayList; import java.util.Random; - -import org.bukkit.BlockChangeDelegate; // CraftBukkit +// CraftBukkit start +import org.bukkit.BlockChangeDelegate; +import org.bukkit.Location; +import org.bukkit.TreeType; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; +import org.bukkit.event.world.StructureGrowEvent; +// Craftbukkit end public class BlockSapling extends BlockFlower { @@ -22,7 +29,7 @@ public class BlockSapling extends BlockFlower { if ((l & 8) == 0) { world.setData(i, j, k, l | 8); } else { - this.b(world, i, j, k, random); + this.b(world, i, j, k, random, false, null, null); // Craftbukkit - added bonemeal, player and itemstack } } } @@ -33,7 +40,8 @@ public class BlockSapling extends BlockFlower { return j == 1 ? 63 : (j == 2 ? 79 : super.a(i, j)); } - public void b(World world, int i, int j, int k, Random random) { + // CraftBukkit - added bonemeal, player and itemstack + public void b(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) { int l = world.getData(i, j, k) & 3; world.setRawTypeId(i, j, k, 0); @@ -41,21 +49,28 @@ public class BlockSapling extends BlockFlower { // CraftBukkit start - fixes client updates on recently grown trees boolean grownTree; BlockChangeWithNotify delegate = new BlockChangeWithNotify(world); - + StructureGrowEvent event = null; + Location location = new Location(world.getWorld(), i, j, k); // All of these are 'false' because we need the 'raw' calls so the block-delegate works if (l == 1) { - grownTree = new WorldGenTaiga2(false).generate(delegate, random, i, j, k); + event = new StructureGrowEvent(location, TreeType.REDWOOD, bonemeal, player, new ArrayList()); + grownTree = new WorldGenTaiga2(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld()); } else if (l == 2) { - grownTree = new WorldGenForest(false).generate(delegate, random, i, j, k); + event = new StructureGrowEvent(location, TreeType.BIRCH, bonemeal, player, new ArrayList()); + grownTree = new WorldGenForest(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld()); } else { if (random.nextInt(10) == 0) { - grownTree = new WorldGenBigTree(false).generate(delegate, random, i, j, k); + event = new StructureGrowEvent(location, TreeType.BIG_TREE, bonemeal, player, new ArrayList()); + grownTree = new WorldGenBigTree(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld()); } else { - grownTree = new WorldGenTrees(false).generate(delegate, random, i, j, k); + event = new StructureGrowEvent(location, TreeType.TREE, bonemeal, player, new ArrayList()); + grownTree = new WorldGenTrees(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld()); } } - - if (!grownTree) { + if (event == null) { + return; + } + if (!grownTree || event.isCancelled()) { world.setRawTypeIdAndData(i, j, k, this.id, l); } // CraftBukkit end @@ -69,7 +84,9 @@ public class BlockSapling extends BlockFlower { private class BlockChangeWithNotify implements BlockChangeDelegate { World world; - BlockChangeWithNotify(World world) { this.world = world; } + BlockChangeWithNotify(World world) { + this.world = world; + } public boolean setRawTypeId(int x, int y, int z, int type) { return this.world.setTypeId(x, y, z, type); diff --git a/src/main/java/net/minecraft/server/ItemDye.java b/src/main/java/net/minecraft/server/ItemDye.java index 4fab72fe5d..aa4c8daa41 100644 --- a/src/main/java/net/minecraft/server/ItemDye.java +++ b/src/main/java/net/minecraft/server/ItemDye.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import org.bukkit.entity.Player; // Craftbukkit + public class ItemDye extends Item { public static final String[] a = new String[] { "black", "red", "green", "brown", "blue", "purple", "cyan", "silver", "gray", "pink", "lime", "yellow", "lightBlue", "magenta", "orange", "white"}; @@ -26,16 +28,23 @@ public class ItemDye extends Item { if (i1 == Block.SAPLING.id) { if (!world.isStatic) { - ((BlockSapling) Block.SAPLING).b(world, i, j, k, world.random); - --itemstack.count; + // Craftbukkit start + Player player = (entityhuman instanceof EntityPlayer) ? (Player)entityhuman.getBukkitEntity() : null; + ((BlockSapling) Block.SAPLING).b(world, i, j, k, world.random, true, player, itemstack); + //--itemstack.count; - called later if the bonemeal attempt was succesful + // Craftbukkit end } return true; } if (i1 == Block.BROWN_MUSHROOM.id || i1 == Block.RED_MUSHROOM.id) { - if (!world.isStatic && ((BlockMushroom) Block.byId[i1]).b(world, i, j, k, world.random)) { - --itemstack.count; + // Craftbukkit start + if (!world.isStatic) { + Player player = (entityhuman instanceof EntityPlayer) ? (Player)entityhuman.getBukkitEntity() : null; + ((BlockMushroom) Block.byId[i1]).b(world, i, j, k, world.random, true, player, itemstack); + //--itemstack.count; - called later if the bonemeal attempt was succesful + // Craftbukkit end } return true; diff --git a/src/main/java/net/minecraft/server/WorldGenBigTree.java b/src/main/java/net/minecraft/server/WorldGenBigTree.java index 17ad929495..0407b8f53c 100644 --- a/src/main/java/net/minecraft/server/WorldGenBigTree.java +++ b/src/main/java/net/minecraft/server/WorldGenBigTree.java @@ -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; } } diff --git a/src/main/java/net/minecraft/server/WorldGenForest.java b/src/main/java/net/minecraft/server/WorldGenForest.java index 5903c9064e..8b014d28a6 100644 --- a/src/main/java/net/minecraft/server/WorldGenForest.java +++ b/src/main/java/net/minecraft/server/WorldGenForest.java @@ -2,7 +2,14 @@ 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; +import org.bukkit.material.MaterialData; +// CraftBukkit end public class WorldGenForest extends WorldGenerator { @@ -16,10 +23,10 @@ public class WorldGenForest 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) + 5; boolean flag = true; @@ -60,8 +67,15 @@ public class WorldGenForest 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; for (i2 = j - 3 + l; i2 <= j + l; ++i2) { @@ -75,7 +89,16 @@ public class WorldGenForest 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, 2); + // Craftbukkit start + if (event == null) { + this.a(world, l1, i2, k2, Block.LEAVES.id, 2); + } else { + BlockState leavesState = bukkitWorld.getBlockAt(l1, i2, k2).getState(); + leavesState.setTypeId(Block.LEAVES.id); + leavesState.setData(new MaterialData(Block.LEAVES.id, (byte) 2)); + event.getBlocks().add(leavesState); + } + // Craftbukkit end } } } @@ -84,10 +107,31 @@ public class WorldGenForest 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, 2); + // Craftbukkit start + if (event == null) { + this.a(world, i, j + i2, k, Block.LOG.id, 2); + } else { + BlockState logState = bukkitWorld.getBlockAt(i, j + i2, k).getState(); + logState.setTypeId(Block.LOG.id); + logState.setData(new MaterialData(Block.LOG.id, (byte) 2)); + 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; diff --git a/src/main/java/net/minecraft/server/WorldGenHugeMushroom.java b/src/main/java/net/minecraft/server/WorldGenHugeMushroom.java index 27f867473e..1da757d884 100644 --- a/src/main/java/net/minecraft/server/WorldGenHugeMushroom.java +++ b/src/main/java/net/minecraft/server/WorldGenHugeMushroom.java @@ -1,6 +1,13 @@ package net.minecraft.server; import java.util.Random; +// Craftbukkit start +import org.bukkit.Bukkit; +import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.event.world.StructureGrowEvent; +import org.bukkit.material.MaterialData; +// Craftbukkit end public class WorldGenHugeMushroom extends WorldGenerator { @@ -12,7 +19,13 @@ public class WorldGenHugeMushroom extends WorldGenerator { public WorldGenHugeMushroom() {} + // CraftBukkit start - delegate to grow() public boolean a(World world, Random random, int i, int j, int k) { + return grow(world, random, i, j, k, null, null, null); + } + + public boolean grow(World world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) { + // CraftBukkit end int l = random.nextInt(2); if (this.a >= 0) { @@ -58,7 +71,15 @@ public class WorldGenHugeMushroom extends WorldGenerator { } else if (!Block.BROWN_MUSHROOM.canPlace(world, i, j, k)) { return false; } else { - 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 j2 = j + i1; if (l == 1) { @@ -138,7 +159,16 @@ public class WorldGenHugeMushroom extends WorldGenerator { } if ((l2 != 0 || j >= j + i1 - 1) && !Block.o[world.getTypeId(i2, k1, k2)]) { - world.setRawTypeIdAndData(i2, k1, k2, Block.BIG_MUSHROOM_1.id + l, l2); + // Craftbukkit start + if (event == null) { + world.setRawTypeIdAndData(i2, k1, k2, Block.BIG_MUSHROOM_1.id + l, l2); + } 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); + } + // Craftbukkit end } } } @@ -147,10 +177,31 @@ public class WorldGenHugeMushroom extends WorldGenerator { for (k1 = 0; k1 < i1; ++k1) { l1 = world.getTypeId(i, j + k1, k); if (!Block.o[l1]) { - world.setRawTypeIdAndData(i, j + k1, k, Block.BIG_MUSHROOM_1.id + l, 10); + // Craftbukkit start + if (event == null) { + world.setRawTypeIdAndData(i, j + k1, k, Block.BIG_MUSHROOM_1.id + l, 10); + } 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); + } + // 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; } } diff --git a/src/main/java/net/minecraft/server/WorldGenTaiga2.java b/src/main/java/net/minecraft/server/WorldGenTaiga2.java index b6cf455579..c20ffc01a3 100644 --- a/src/main/java/net/minecraft/server/WorldGenTaiga2.java +++ b/src/main/java/net/minecraft/server/WorldGenTaiga2.java @@ -2,7 +2,14 @@ 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; +import org.bukkit.material.MaterialData; +// CraftBukkit end public class WorldGenTaiga2 extends WorldGenerator { @@ -16,10 +23,10 @@ public class WorldGenTaiga2 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(4) + 6; int i1 = 1 + random.nextInt(2); @@ -61,7 +68,15 @@ public class WorldGenTaiga2 extends WorldGenerator { } else { l1 = world.getTypeId(i, j - 1, k); if ((l1 == Block.GRASS.id || l1 == 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 k2 = random.nextInt(2); i2 = 1; byte b0 = 0; @@ -79,7 +94,16 @@ public class WorldGenTaiga2 extends WorldGenerator { int i4 = l3 - k; if ((Math.abs(k3) != k2 || Math.abs(i4) != k2 || k2 <= 0) && !Block.o[world.getTypeId(i3, j3, l3)]) { - this.a(world, i3, j3, l3, Block.LEAVES.id, 1); + // Craftbukkit start + if (event == null) { + this.a(world, i3, j3, l3, Block.LEAVES.id, 1); + } else { + BlockState leavesState = bukkitWorld.getBlockAt(i3, j3, l3).getState(); + leavesState.setTypeId(Block.LEAVES.id); + leavesState.setData(new MaterialData(Block.LEAVES.id, (byte) 1)); + event.getBlocks().add(leavesState); + } + // Craftbukkit end } } } @@ -101,10 +125,31 @@ public class WorldGenTaiga2 extends WorldGenerator { for (j3 = 0; j3 < l - j2; ++j3) { i3 = world.getTypeId(i, j + j3, k); if (i3 == 0 || i3 == Block.LEAVES.id) { - this.a(world, i, j + j3, k, Block.LOG.id, 1); + // Craftbukkit start + if (event == null) { + this.a(world, i, j + j3, k, Block.LOG.id, 1); + } else { + BlockState logState = bukkitWorld.getBlockAt(i, j + j3, k).getState(); + logState.setTypeId(Block.LOG.id); + logState.setData(new MaterialData(Block.LOG.id, (byte) 1)); + 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; diff --git a/src/main/java/net/minecraft/server/WorldGenTrees.java b/src/main/java/net/minecraft/server/WorldGenTrees.java index 15450e410f..c9c81b64ba 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; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 4bc1552433..553bb1bd5c 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -348,16 +348,16 @@ public class CraftWorld implements World { public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { switch (type) { case BIG_TREE: - return new WorldGenBigTree(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + return new WorldGenBigTree(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null); case BIRCH: - return new WorldGenForest(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + return new WorldGenForest(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null); case REDWOOD: - return new WorldGenTaiga2(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + return new WorldGenTaiga2(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null); case TALL_REDWOOD: return new WorldGenTaiga1().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); case TREE: default: - return new WorldGenTrees(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + return new WorldGenTrees(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null); } }