From 10ab7b96edb85c90dd480aa718a59d82682e091c Mon Sep 17 00:00:00 2001 From: Tahg Date: Wed, 8 Feb 2012 21:26:49 -0500 Subject: [PATCH] Made steps fire a BlockPlace event. Fixes BUKKIT-394 --- .../java/net/minecraft/server/ItemBlock.java | 27 ++++++------------- .../java/net/minecraft/server/ItemStep.java | 7 +++-- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/minecraft/server/ItemBlock.java b/src/main/java/net/minecraft/server/ItemBlock.java index f910bee72b..1f65bf73e5 100644 --- a/src/main/java/net/minecraft/server/ItemBlock.java +++ b/src/main/java/net/minecraft/server/ItemBlock.java @@ -58,29 +58,18 @@ public class ItemBlock extends Item { return false; } else if (j == world.height - 1 && Block.byId[this.id].material.isBuildable()) { return false; - } else if (world.mayPlace(this.id, i, j, k, false, l)) { - Block block = Block.byId[this.id]; + } + // CraftBukkit start + int id = (l == -1 && itemstack.getItem() instanceof ItemStep) ? Block.DOUBLE_STEP.id : this.id; + if (id != this.id || world.mayPlace(this.id, i, j, k, false, l)) { + Block block = Block.byId[id]; - // CraftBukkit start - This executes the placement of the block CraftBlockState replacedBlockState = CraftBlockState.getBlockState(world, i, j, k); - // There are like 30 combinations you can mix and match steps and double steps - // of different materials, so there are a lot of different cases of what - // would happen if you place x step onto another y step, so let's just keep - // track of the entire state - CraftBlockState blockStateBelow = null; - // Toggles whether the normal or the block below is used for the place event - boolean eventUseBlockBelow = false; - if ((world.getTypeId(i, j - 1, k) == Block.STEP.id || world.getTypeId(i, j - 1, k) == Block.DOUBLE_STEP.id) && (itemstack.id == Block.DOUBLE_STEP.id || itemstack.id == Block.STEP.id)) { - blockStateBelow = CraftBlockState.getBlockState(world, i, j - 1, k); - // Step is placed on step, forms a doublestep replacing the original step, so we need the lower block - eventUseBlockBelow = itemstack.id == Block.STEP.id && blockStateBelow.getTypeId() == Block.STEP.id; - } - world.suppressPhysics = true; - world.setTypeIdAndData(i, j, k, this.id, this.filterData(itemstack.getData())); - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, eventUseBlockBelow ? blockStateBelow : replacedBlockState, clickedX, clickedY, clickedZ, block); - int id = world.getTypeId(i, j, k); + world.setTypeIdAndData(i, j, k, id, this.filterData(itemstack.getData())); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ, block); + id = world.getTypeId(i, j, k); int data = world.getData(i, j, k); replacedBlockState.update(true); world.suppressPhysics = false; diff --git a/src/main/java/net/minecraft/server/ItemStep.java b/src/main/java/net/minecraft/server/ItemStep.java index 97b6c27b31..e59b67ec04 100644 --- a/src/main/java/net/minecraft/server/ItemStep.java +++ b/src/main/java/net/minecraft/server/ItemStep.java @@ -36,12 +36,15 @@ public class ItemStep extends ItemBlock { int j1 = world.getData(i, j, k); if (l == 1 && i1 == Block.STEP.id && j1 == itemstack.getData()) { + // CraftBukkit start - handle this in super + /* if (world.setTypeIdAndData(i, j, k, Block.DOUBLE_STEP.id, j1)) { world.makeSound((double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), Block.DOUBLE_STEP.stepSound.getName(), (Block.DOUBLE_STEP.stepSound.getVolume1() + 1.0F) / 2.0F, Block.DOUBLE_STEP.stepSound.getVolume2() * 0.8F); --itemstack.count; } - - return true; + */ + return super.a(itemstack, entityhuman, world, i, j, k, -1); + // CraftBukkit end } else { return super.a(itemstack, entityhuman, world, i, j, k, l); }