From 8319eb6d91552d3e7c0cdf0c79d2ef3c1dedc857 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 17 Nov 2013 16:15:22 +0100 Subject: [PATCH] Added an item->block mapping for LocalPlayer.getBlockInHand(). --- .../sk89q/worldedit/bukkit/BukkitUtil.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java index 483198211..cfc9f8c1d 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java @@ -24,6 +24,11 @@ import java.util.List; import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.blocks.BlockType; +import com.sk89q.worldedit.blocks.ItemID; +import com.sk89q.worldedit.blocks.SkullBlock; +import org.bukkit.DyeColor; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.block.Block; @@ -45,6 +50,7 @@ import com.sk89q.worldedit.bukkit.entity.BukkitExpOrb; import com.sk89q.worldedit.bukkit.entity.BukkitItem; import com.sk89q.worldedit.bukkit.entity.BukkitPainting; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.Dye; public class BukkitUtil { private BukkitUtil() { @@ -164,6 +170,25 @@ public class BukkitUtil { return new BaseBlock(typeId, itemStack.getDurability()); } + switch (typeId) { + case ItemID.INK_SACK: + final Dye materialData = (Dye) itemStack.getData(); + if (materialData.getColor() == DyeColor.BROWN) { + return new BaseBlock(BlockID.COCOA_PLANT, -1); + } + break; + + case ItemID.HEAD: + return new SkullBlock(0, (byte) itemStack.getDurability()); + + default: + final BaseBlock baseBlock = BlockType.getBlockForItem(typeId); + if (baseBlock != null) { + return baseBlock; + } + break; + } + throw new NotABlockException(typeId); } }