diff --git a/src/main/java/net/minecraft/server/BlockCactus.java b/src/main/java/net/minecraft/server/BlockCactus.java index b9da7d2af4..c7235365ad 100644 --- a/src/main/java/net/minecraft/server/BlockCactus.java +++ b/src/main/java/net/minecraft/server/BlockCactus.java @@ -26,7 +26,7 @@ public class BlockCactus extends Block { int i1 = world.getData(i, j, k); if (i1 == 15) { - world.setTypeId(i, j + 1, k, this.id); + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j + 1, k, this.id, 0); // CraftBukkit world.setData(i, j, k, 0); } else { world.setData(i, j, k, i1 + 1); diff --git a/src/main/java/net/minecraft/server/BlockCrops.java b/src/main/java/net/minecraft/server/BlockCrops.java index 818d2efd9e..dfdbc746a3 100644 --- a/src/main/java/net/minecraft/server/BlockCrops.java +++ b/src/main/java/net/minecraft/server/BlockCrops.java @@ -26,8 +26,7 @@ public class BlockCrops extends BlockFlower { float f = this.i(world, i, j, k); if (random.nextInt((int) (25.0F / f) + 1) == 0) { - ++l; - world.setData(i, j, k, l); + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j, k, this.id, ++l); // CraftBukkit } } } diff --git a/src/main/java/net/minecraft/server/BlockNetherWart.java b/src/main/java/net/minecraft/server/BlockNetherWart.java index f496853420..c6e635ab31 100644 --- a/src/main/java/net/minecraft/server/BlockNetherWart.java +++ b/src/main/java/net/minecraft/server/BlockNetherWart.java @@ -26,8 +26,7 @@ public class BlockNetherWart extends BlockFlower { BiomeBase biomebase = worldchunkmanager.getBiome(i, k); if (biomebase instanceof BiomeHell && random.nextInt(15) == 0) { - ++l; - world.setData(i, j, k, l); + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j, k, this.id, ++l); // CraftBukkit } } } diff --git a/src/main/java/net/minecraft/server/BlockReed.java b/src/main/java/net/minecraft/server/BlockReed.java index 21afe6a332..58f90fab6b 100644 --- a/src/main/java/net/minecraft/server/BlockReed.java +++ b/src/main/java/net/minecraft/server/BlockReed.java @@ -25,7 +25,7 @@ public class BlockReed extends Block { int i1 = world.getData(i, j, k); if (i1 == 15) { - world.setTypeId(i, j + 1, k, this.id); + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j + 1, k, this.id, 0); // CraftBukkit world.setData(i, j, k, 0); } else { world.setData(i, j, k, i1 + 1); diff --git a/src/main/java/net/minecraft/server/BlockStem.java b/src/main/java/net/minecraft/server/BlockStem.java index 388077778f..8736f2cd4b 100644 --- a/src/main/java/net/minecraft/server/BlockStem.java +++ b/src/main/java/net/minecraft/server/BlockStem.java @@ -28,8 +28,7 @@ public class BlockStem extends BlockFlower { int l = world.getData(i, j, k); if (l < 7) { - ++l; - world.setData(i, j, k, l); + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j, k, this.id, ++l); // CraftBukkit } else { if (world.getTypeId(i - 1, j, k) == this.a.id) { return; @@ -70,7 +69,7 @@ public class BlockStem extends BlockFlower { int l1 = world.getTypeId(j1, j - 1, k1); if (world.getTypeId(j1, j, k1) == 0 && (l1 == Block.SOIL.id || l1 == Block.DIRT.id || l1 == Block.GRASS.id)) { - world.setTypeId(j1, j, k1, this.a.id); + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, j1, j, k1, this.a.id, 0); // CraftBukkit } } } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java index 5519afea44..34d8290f4f 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -80,9 +80,11 @@ public class CraftBlockState implements BlockState { } public boolean setTypeId(final int type) { - this.type = type; + if (this.type != type) { + this.type = type; - createData((byte) 0); + createData((byte) 0); + } return true; } @@ -126,7 +128,7 @@ public class CraftBlockState implements BlockState { } private void createData(final byte data) { - Material mat = Material.getMaterial(type); + Material mat = getType(); if (mat == null || mat.getData() == null) { this.data = new MaterialData(type, data); } else { @@ -142,8 +144,8 @@ public class CraftBlockState implements BlockState { return new Location(world, x, y, z); } - public void setData(byte data) { - createData(data); + public void setRawData(byte data) { + this.data.setData(data); } @Override diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 9087d6ffae..a829d2ef9a 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -52,6 +52,7 @@ import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBlockState; import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.inventory.CraftItemStack; @@ -424,7 +425,7 @@ public class CraftEventFactory { public static boolean handleProjectileEvent(Projectile projectile, Entity target, DamageSource damagesource, int damage) { if (target instanceof EntityLiving || target instanceof EntityComplexPart || target instanceof EntityEnderCrystal) { org.bukkit.entity.Entity damagee = target.getBukkitEntity(); - + EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, damage); Bukkit.getPluginManager().callEvent(event); @@ -438,4 +439,18 @@ public class CraftEventFactory { return !projectile.doesBounce(); } + + public static void handleBlockGrowEvent(World world, int x, int y, int z, int type, int data) { + Block block = world.getWorld().getBlockAt(x, y, z); + CraftBlockState state = (CraftBlockState) block.getState(); + state.setTypeId(type); + state.setRawData((byte) data); + + BlockGrowEvent event = new BlockGrowEvent(block, state); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + state.update(true); + } + } }