From a1cf6eb6da803783444f89026d2a55d4b0605393 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sat, 17 Sep 2011 21:50:06 -0700 Subject: [PATCH] Allow //replace to ignore from block damage values (and force them to not be ignored with the -f flag) --- .../java/com/sk89q/worldedit/EditSession.java | 4 +-- .../java/com/sk89q/worldedit/WorldEdit.java | 27 +++++++++++++++---- .../com/sk89q/worldedit/blocks/BaseBlock.java | 3 ++- .../worldedit/commands/RegionCommands.java | 3 ++- .../worldedit/commands/UtilityCommands.java | 3 ++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 27b4a6206..0531b16c8 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -207,9 +207,9 @@ public class EditSession { if (BlockType.usesData(type)) { if (fastMode) { - result = world.setTypeIdAndDataFast(pt, type, block.getData()); + result = world.setTypeIdAndDataFast(pt, type, block.getData() > -1 ? block.getData() : 0); } else { - result = world.setTypeIdAndData(pt, type, block.getData()); + result = world.setTypeIdAndData(pt, type, block.getData() > -1 ? block.getData() : 0); } } else { if (fastMode) { diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 0fef4f0f9..87eeaefe8 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -246,6 +246,11 @@ public class WorldEdit { } } + public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed) + throws UnknownItemException, DisallowedItemException { + return getBlock(player, arg, allAllowed, false); + } + /** * Get an item ID from an item name or an item ID number. * @@ -256,7 +261,8 @@ public class WorldEdit { * @throws UnknownItemException * @throws DisallowedItemException */ - public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed) + public BaseBlock getBlock(LocalPlayer player, String arg, + boolean allAllowed, boolean allowNoData) throws UnknownItemException, DisallowedItemException { BlockType blockType; arg = arg.replace("_", " "); @@ -307,8 +313,8 @@ public class WorldEdit { if (data == -1) { // Block data not yet detected // Parse the block data (optional) try { - data = args1.length > 1 ? Integer.parseInt(args1[1]) : 0; - if (data > 15 || data < 0) { + data = args1.length > 1 ? Integer.parseInt(args1[1]) : (allowNoData ? -1 : 0); + if (data > 15 || (data < 0 && !(allAllowed && data == -1))) { data = 0; } } catch (NumberFormatException e) { @@ -344,6 +350,11 @@ public class WorldEdit { case COBBLESTONE: data = 3; break; + case BRICK: + data = 4; + break; + case STONE_BRICK: + data = 5; default: throw new InvalidItemException(arg, "Invalid step type '" + args1[1] + "'"); @@ -425,16 +436,22 @@ public class WorldEdit { return getBlock(player, id, false); } - public Set getBlocks (LocalPlayer player, String list, boolean allAllowed) + public Set getBlocks (LocalPlayer player, String list, + boolean allAllowed, boolean allowNoData) throws DisallowedItemException, UnknownItemException { String[] items = list.split(","); Set blocks = new HashSet(); for (String id : items) { - blocks.add(getBlock(player, id, allAllowed)); + blocks.add(getBlock(player, id, allAllowed, allowNoData)); } return blocks; } + public Set getBlocks(LocalPlayer player, String list, boolean allAllowed) + throws DisallowedItemException, UnknownItemException { + return getBlocks(player, list, allAllowed); + } + public Set getBlocks(LocalPlayer player, String list) throws DisallowedItemException, UnknownItemException { return getBlocks(player, list, false); diff --git a/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java b/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java index e8dfded05..d29a65c65 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java @@ -129,7 +129,8 @@ public class BaseBlock { if (!(o instanceof BaseBlock)) { return false; } - return (type == ((BaseBlock)o).type) && (data == ((BaseBlock)o).data); + return (type == ((BaseBlock)o).type) + && (data == ((BaseBlock)o).data || data == -1 || ((BaseBlock)o).data == -1); } @Override diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index 7d6d052dd..a75a2864a 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -73,6 +73,7 @@ public class RegionCommands { aliases = {"/replace"}, usage = "[from-block] ", desc = "Replace all blocks in the selection with another", + flags = "f", min = 1, max = 2 ) @@ -88,7 +89,7 @@ public class RegionCommands { from = null; to = we.getBlockPattern(player, args.getString(0)); } else { - from = we.getBlocks(player, args.getString(0), true); + from = we.getBlocks(player, args.getString(0), true, !args.hasFlag('f')); to = we.getBlockPattern(player, args.getString(1)); } diff --git a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java index 6b16a1261..c4e24d632 100644 --- a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java @@ -228,6 +228,7 @@ public class UtilityCommands { aliases = {"/replacenear", "replacenear"}, usage = " ", desc = "Replace nearby blocks", + flags = "f", min = 3, max = 3 ) @@ -245,7 +246,7 @@ public class UtilityCommands { from = null; to = we.getBlockPattern(player, args.getString(1)); } else { - from = we.getBlocks(player, args.getString(1), true); + from = we.getBlocks(player, args.getString(1), true, !args.hasFlag('f')); to = we.getBlockPattern(player, args.getString(2)); }