From 5e43c61fad9c6620b20518b120ac0448387f2ee5 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 9 Dec 2011 16:11:56 +0000 Subject: Implemented onStructureGrow event, thanks to md-5. --- .../java/net/minecraft/server/WorldGenTaiga2.java | 59 +++++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) (limited to 'src/main/java/net/minecraft/server/WorldGenTaiga2.java') diff --git a/src/main/java/net/minecraft/server/WorldGenTaiga2.java b/src/main/java/net/minecraft/server/WorldGenTaiga2.java index b6cf4555..c20ffc01 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; -- cgit v1.2.3