From 28e9f1ac43b5c1218a3f6c742391fde131981a6b Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 29 Oct 2012 12:38:34 -0500 Subject: [PATCH] Get skull data before destroying block. Fixes BUKKIT-2723 Skull blocks store their type in a tile entity and use their block data as rotation. When breaking a block the block data is used for determining what item to drop. Simply changing this to use the skull method for getting their drop data is not enough because their tile entity is already gone. Therefore we have to special case skulls to get the correct data _and_ get that data before breaking the block. By: Travis Watkins --- .../java/org/bukkit/craftbukkit/CraftWorld.java | 6 +++++- .../bukkit/craftbukkit/block/CraftBlock.java | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 277c3b3dec..2ca3078d97 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1083,7 +1083,11 @@ public class CraftWorld implements World { int blockY = block.getY(); int blockZ = block.getZ(); // following code is lifted from Explosion.a(boolean), and modified - net.minecraft.server.Block.byId[blockId].dropNaturally(this.world, blockX, blockY, blockZ, block.getData(), yield, 0); + int data = block.getData(); + if (blockId == net.minecraft.server.Block.SKULL.id) { + data = net.minecraft.server.Block.SKULL.getDropData(this.world, blockX, blockY, blockZ); + } + net.minecraft.server.Block.byId[blockId].dropNaturally(this.world, blockX, blockY, blockZ, data, yield, 0); block.setType(org.bukkit.Material.AIR); // not sure what this does, seems to have something to do with the 'base' material of a block. // For example, WOODEN_STAIRS does something with WOOD in this method diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index c5c11fddb1..b1eb4fc6ac 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -342,15 +342,22 @@ public class CraftBlock implements Block { } public boolean breakNaturally() { + // Order matters here, need to drop before setting to air so skulls can get their data net.minecraft.server.Block block = net.minecraft.server.Block.byId[this.getTypeId()]; byte data = getData(); + boolean result = false; + + if (block != null) { + if (block.id == net.minecraft.server.Block.SKULL.id) { + data = (byte) block.getDropData(chunk.getHandle().world, x, y, z); + } + + block.dropNaturally(chunk.getHandle().world, x, y, z, data, 1.0F, 0); + result = true; + } setTypeId(Material.AIR.getId()); - if (block != null) { - block.dropNaturally(chunk.getHandle().world, x, y, z, data, 1.0F, 0); - return true; - } - return false; + return result; } public boolean breakNaturally(ItemStack item) {