From 71a475f0764c459dffbcbc32db36953b18a67afa Mon Sep 17 00:00:00 2001 From: Travis Watkins Date: Sun, 31 Mar 2013 19:18:42 -0500 Subject: [PATCH] Don't update physics when block place is cancelled. Fixes BUKKIT-3939 When a block placement happens we currently update physics on the attempted placement and update again if the placement is cancelled. To correct the first one we simply set the block without applying physics. To correct the second we have to add a new method to BlockState that lets us update without applying physics and use this method method when putting the block back. --- src/main/java/net/minecraft/server/ItemBlock.java | 4 ++-- .../java/org/bukkit/craftbukkit/block/CraftBeacon.java | 4 ++-- .../org/bukkit/craftbukkit/block/CraftBlockState.java | 10 +++++++--- .../bukkit/craftbukkit/block/CraftBrewingStand.java | 4 ++-- .../java/org/bukkit/craftbukkit/block/CraftChest.java | 4 ++-- .../bukkit/craftbukkit/block/CraftCommandBlock.java | 4 ++-- .../org/bukkit/craftbukkit/block/CraftDispenser.java | 4 ++-- .../org/bukkit/craftbukkit/block/CraftDropper.java | 4 ++-- .../org/bukkit/craftbukkit/block/CraftFurnace.java | 4 ++-- .../java/org/bukkit/craftbukkit/block/CraftHopper.java | 4 ++-- .../java/org/bukkit/craftbukkit/block/CraftSign.java | 4 ++-- .../java/org/bukkit/craftbukkit/block/CraftSkull.java | 4 ++-- 12 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/minecraft/server/ItemBlock.java b/src/main/java/net/minecraft/server/ItemBlock.java index ba2feafde1..01c06af272 100644 --- a/src/main/java/net/minecraft/server/ItemBlock.java +++ b/src/main/java/net/minecraft/server/ItemBlock.java @@ -80,11 +80,11 @@ public class ItemBlock extends Item { org.bukkit.block.BlockState blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(world, x, y, z); world.callingPlaceEvent = true; - world.setTypeIdAndData(x, y, z, id, data, 3); + world.setTypeIdAndData(x, y, z, id, data, 2); org.bukkit.event.block.BlockPlaceEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockstate, clickedX, clickedY, clickedZ); if (event.isCancelled() || !event.canBuild()) { - blockstate.update(true); + blockstate.update(true, false); world.callingPlaceEvent = false; return false; } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java index c39857eca7..178f7eb027 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java @@ -24,8 +24,8 @@ public class CraftBeacon extends CraftBlockState implements Beacon { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { beacon.update(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java index d2350452ab..2072db2801 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -113,17 +113,21 @@ public class CraftBlockState implements BlockState { } public boolean update(boolean force) { + return update(force, true); + } + + public boolean update(boolean force, boolean applyPhysics) { Block block = getBlock(); - if (block.getType() != this.getType()) { + if (block.getType() != getType()) { if (force) { - block.setTypeId(this.getTypeId()); + block.setTypeId(getTypeId(), applyPhysics); } else { return false; } } - block.setData(getRawData()); + block.setData(getRawData(), applyPhysics); world.getHandle().notify(x, y, z); return true; diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java index 074473cd5d..d306c3afe1 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java @@ -21,8 +21,8 @@ public class CraftBrewingStand extends CraftBlockState implements BrewingStand { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { brewingStand.update(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java b/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java index 60dea4398c..6ae2b303ea 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java @@ -61,8 +61,8 @@ public class CraftChest extends CraftBlockState implements Chest { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { chest.update(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java index 4572438d69..c68e27cac0 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java @@ -35,8 +35,8 @@ public class CraftCommandBlock extends CraftBlockState implements CommandBlock { this.name = name != null ? name : "@"; } - public boolean update(boolean forced) { - boolean result = super.update(forced); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { commandBlock.b(command); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java b/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java index 9561ea9bd5..183ec43aa0 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java @@ -39,8 +39,8 @@ public class CraftDispenser extends CraftBlockState implements Dispenser { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { dispenser.update(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java b/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java index 85b9af64c7..67da932335 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java @@ -36,8 +36,8 @@ public class CraftDropper extends CraftBlockState implements Dropper { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { dropper.update(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java index d50604d991..8c548f13cd 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java @@ -21,8 +21,8 @@ public class CraftFurnace extends CraftBlockState implements Furnace { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { furnace.update(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java b/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java index 787b609f43..a46c472bd7 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java @@ -21,8 +21,8 @@ public class CraftHopper extends CraftBlockState implements Hopper { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { hopper.update(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java index 8e8a1c5825..16471009fa 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java @@ -31,8 +31,8 @@ public class CraftSign extends CraftBlockState implements Sign { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { for(int i = 0; i < 4; i++) { diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java index 0f3e0d8ff1..4e121a3dfd 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java @@ -181,8 +181,8 @@ public class CraftSkull extends CraftBlockState implements Skull { } @Override - public boolean update(boolean force) { - boolean result = super.update(force); + public boolean update(boolean force, boolean applyPhysics) { + boolean result = super.update(force, applyPhysics); if (result) { skull.setSkullType(getSkullType(skullType), player);