From d467bf13861f7a07d8118c4e8062528c72756e44 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 1 Dec 2013 23:57:09 +0100 Subject: [PATCH] Added data value mappings for certain blocks and made all other block types wildcard matches. --- .../com/sk89q/worldedit/blocks/BlockType.java | 28 +++++++++++++++++-- .../sk89q/worldedit/bukkit/BukkitUtil.java | 9 +++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java index 3eeff5ef9..db247687a 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java @@ -284,7 +284,25 @@ public enum BlockType { } private static Map itemBlockMapping = new HashMap(); + private static Map dataItemBlockMapping = new HashMap(); static { + for (int data = 0; data < 16; ++data) { + //dataItemBlockMapping.put(typeDataKey(BlockID.DIRT, data), new BaseBlock(BlockID.DIRT, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.WOOD, data), new BaseBlock(BlockID.WOOD, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.SAND, data), new BaseBlock(BlockID.SAND, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.SANDSTONE, data), new BaseBlock(BlockID.SANDSTONE, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.LONG_GRASS, data), new BaseBlock(BlockID.LONG_GRASS, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.CLOTH, data), new BaseBlock(BlockID.CLOTH, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.SILVERFISH_BLOCK, data), new BaseBlock(BlockID.SILVERFISH_BLOCK, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.STONE_BRICK, data), new BaseBlock(BlockID.STONE_BRICK, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.COBBLESTONE_WALL, data), new BaseBlock(BlockID.COBBLESTONE_WALL, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.STAINED_CLAY, data), new BaseBlock(BlockID.STAINED_CLAY, data)); + dataItemBlockMapping.put(typeDataKey(BlockID.CARPET, data), new BaseBlock(BlockID.CARPET, data)); + //dataItemBlockMapping.put(typeDataKey(BlockID.FLOWER, data), new BaseBlock(BlockID.FLOWER, data)); + //dataItemBlockMapping.put(typeDataKey(BlockID.LARGE_FLOWER, data), new BaseBlock(BlockID.LARGE_FLOWER, data)); + //dataItemBlockMapping.put(typeDataKey(BlockID.STAINED_GLASS, data), new BaseBlock(BlockID.STAINED_GLASS, data)); + } + itemBlockMapping.put(ItemID.FLINT_AND_TINDER, new BaseBlock(BlockID.FIRE, -1)); itemBlockMapping.put(ItemID.STRING, new BaseBlock(BlockID.TRIPWIRE, -1)); itemBlockMapping.put(ItemID.SEEDS, new BaseBlock(BlockID.CROPS, -1)); @@ -312,8 +330,14 @@ public enum BlockType { itemBlockMapping.put(ItemID.MILK_BUCKET, new BaseBlock(BlockID.SNOW, -1)); // Whoops, spilled the milk } - public static BaseBlock getBlockForItem(int typeId) { - return itemBlockMapping.get(typeId); + public static BaseBlock getBlockForItem(int typeId, int data) { + final BaseBlock block = itemBlockMapping.get(typeId); + + if (block != null) { + return block; + } + + return dataItemBlockMapping.get(typeDataKey(typeId, data)); } /** diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java index cfc9f8c1d..05307ab66 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java @@ -166,9 +166,6 @@ public class BukkitUtil { public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException { final int typeId = itemStack.getTypeId(); - if (world.isValidBlockType(typeId)) { - return new BaseBlock(typeId, itemStack.getDurability()); - } switch (typeId) { case ItemID.INK_SACK: @@ -182,13 +179,17 @@ public class BukkitUtil { return new SkullBlock(0, (byte) itemStack.getDurability()); default: - final BaseBlock baseBlock = BlockType.getBlockForItem(typeId); + final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability()); if (baseBlock != null) { return baseBlock; } break; } + if (world.isValidBlockType(typeId)) { + return new BaseBlock(typeId, -1); + } + throw new NotABlockException(typeId); } }