Direct all BlockPlaceEvents to a singular location. Fixes BUKKIT-3438

By having a single function to process BlockPlacement logic, we make
it so that there is consistent behavior throughout all BlockPlace
events. This should allow for easier troubleshooting and less diffs
in source.

This also fixes BUKKIT-3463 by including the correct coordinates that
were clicked to the event.
This commit is contained in:
feildmaster
2013-01-27 10:44:32 -06:00
parent 528bbbdcd8
commit 899b9c17cc
13 changed files with 57 additions and 141 deletions

View File

@@ -1,7 +1,5 @@
package net.minecraft.server;
import org.bukkit.craftbukkit.block.CraftBlockState; // CraftBukkit
public class ItemSign extends Item {
public ItemSign(int i) {
@@ -11,13 +9,12 @@ public class ItemSign extends Item {
}
public boolean interactWith(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l, float f, float f1, float f2) {
final int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit
if (l == 0) {
return false;
} else if (!world.getMaterial(i, j, k).isBuildable()) {
return false;
} else {
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit
if (l == 1) {
++j;
}
@@ -43,28 +40,20 @@ public class ItemSign extends Item {
} else if (!Block.SIGN_POST.canPlace(world, i, j, k)) {
return false;
} else {
CraftBlockState blockState = CraftBlockState.getBlockState(world, i, j, k); // CraftBukkit
// CraftBukkit start
final Block block;
if (l == 1) {
int i1 = MathHelper.floor((double) ((entityhuman.yaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15;
// CraftBukkit start - sign
world.setRawTypeIdAndData(i, j, k, Block.SIGN_POST.id, i1);
// world.setTypeIdAndData(i, j, k, Block.SIGN_POST.id, i1);
block = Block.SIGN_POST;
l = i1;
} else {
world.setRawTypeIdAndData(i, j, k, Block.WALL_SIGN.id, l);
// world.setTypeIdAndData(i, j, k, Block.WALL_SIGN.id, l);
block = Block.WALL_SIGN;
}
org.bukkit.event.block.BlockPlaceEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ);
if (event.isCancelled() || !event.canBuild()) {
event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false);
if (!ItemBlock.processBlockPlace(world, entityhuman, null, i, j, k, block.id, l, clickedX, clickedY, clickedZ)) {
return false;
} else {
if (l == 1) {
world.update(i, j, k, Block.SIGN_POST.id);
} else {
world.update(i, j, k, Block.WALL_SIGN.id);
}
}
// CraftBukkit end