diff options
author | VictorD <victor.danell@gmail.com> | 2011-01-24 23:22:28 +0100 |
---|---|---|
committer | VictorD <victor.danell@gmail.com> | 2011-01-24 23:22:28 +0100 |
commit | 3477a86995690511723884363a4ea259cd559b0f (patch) | |
tree | 7559f579ae1efa3a76899e4c5ee9e7a281c12268 /src/main | |
parent | 0675ead1692d1569c8ad43e22dff97c5225fa03e (diff) | |
download | craftbukkit-3477a86995690511723884363a4ea259cd559b0f.tar craftbukkit-3477a86995690511723884363a4ea259cd559b0f.tar.gz craftbukkit-3477a86995690511723884363a4ea259cd559b0f.tar.lz craftbukkit-3477a86995690511723884363a4ea259cd559b0f.tar.xz craftbukkit-3477a86995690511723884363a4ea259cd559b0f.zip |
Added getBlockReplacedState to BlockPlaceEvent, in case one wants to see what type of block was there previously.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/net/minecraft/server/ItemBlock.java | 16 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java | 2 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/main/java/net/minecraft/server/ItemBlock.java b/src/main/java/net/minecraft/server/ItemBlock.java index f6a7dac2..eb971249 100644 --- a/src/main/java/net/minecraft/server/ItemBlock.java +++ b/src/main/java/net/minecraft/server/ItemBlock.java @@ -2,8 +2,9 @@ package net.minecraft.server; // CraftBukkit start import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBlockState; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.event.Event.Type; @@ -59,9 +60,12 @@ public class ItemBlock extends Item { return false; } - // CraftBukkit start - store the old data so we can undo it - int oldMaterial = world.a(i, j, k); - int oldData = world.b(i, j, k); + // CraftBukkit start + /* We store the old data so we can undo it. Snow(78) and half-steps(44) are special in that they replace the block itself, + * rather than the block touching the face we clicked on. + */ + org.bukkit.block.Block replacedBlock = (blockClicked.getTypeId() == 78 || blockClicked.getTypeId() == 44) ? blockClicked:blockClicked.getFace(faceClicked); + final BlockState replacedBlockState = new CraftBlockState(replacedBlock); if (world.a(a, i, j, k, false)) { Block block = Block.m[a]; @@ -88,7 +92,7 @@ public class ItemBlock extends Item { // TODO make spawn size configurable boolean canBuild = distanceFromSpawn > 16 || thePlayer.isOp(); - BlockPlaceEvent bpe = new BlockPlaceEvent(eventType, placedBlock, blockClicked, itemInHand, thePlayer, canBuild); + BlockPlaceEvent bpe = new BlockPlaceEvent(eventType, placedBlock, replacedBlockState, blockClicked, itemInHand, thePlayer, canBuild); server.getPluginManager().callEvent(bpe); if (bpe.isCancelled() || !bpe.canBuild()) { @@ -102,7 +106,7 @@ public class ItemBlock extends Item { world.b(i, j - 1, k, 44); } - world.a(i, j, k, oldMaterial, oldData); + world.a(i, j, k, replacedBlockState.getTypeId(), replacedBlockState.getData().getData()); } else { world.f(i, j, k, a); // <-- world.b does this on success (tell the world) diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java index eb5df635..00d5f9fb 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -184,7 +184,7 @@ public class CraftBlockState implements BlockState { private void createData(final byte data) { Material mat = Material.getMaterial(type); - if (mat == null) { + if (mat == null || mat.getData() == null) { this.data = new MaterialData(type, data); } else { this.data = mat.getNewData(data); |