Made steps fire a BlockPlace event. Fixes BUKKIT-394

This commit is contained in:
Tahg
2012-02-08 21:26:49 -05:00
committed by EvilSeph
parent 6abd178ea7
commit 10ab7b96ed
2 changed files with 13 additions and 21 deletions

View File

@@ -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;