From 09a92fa76c73d0a00d1a1ff1c63213db49898b0d Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 20 Dec 2011 11:20:18 +0100 Subject: [PATCH] Added a block/pattern parameter to //hollow. Also made a few variables final and optimized the thickness algo a bit. --- .../java/com/sk89q/worldedit/EditSession.java | 37 +++++++++---------- .../worldedit/commands/RegionCommands.java | 13 +++++-- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 9e0776f46..eae2eb7ae 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2724,27 +2724,29 @@ public class EditSession { }; /** - * Hollows out the region (It's treated as if it was a cuboid if it's not). + * Hollows out the region (Semi-well-defined for non-cuboid selections). * - * @param region - * @param block + * @param region the region to hollow out. + * @param thickness the thickness of the shell to leave (manhattan distance) + * @param patternThe block pattern to use + * * @return number of blocks affected * @throws MaxChangedBlocksException */ - public int hollowOutRegion(Region region, int thickness) throws MaxChangedBlocksException { + public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws MaxChangedBlocksException { int affected = 0; - Set outside = new HashSet(); + final Set outside = new HashSet(); - Vector min = region.getMinimumPoint(); - Vector max = region.getMaximumPoint(); + final Vector min = region.getMinimumPoint(); + final Vector max = region.getMaximumPoint(); - int minX = min.getBlockX(); - int minY = min.getBlockY(); - int minZ = min.getBlockZ(); - int maxX = max.getBlockX(); - int maxY = max.getBlockY(); - int maxZ = max.getBlockZ(); + final int minX = min.getBlockX(); + final int minY = min.getBlockY(); + final int minZ = min.getBlockZ(); + final int maxX = max.getBlockX(); + final int maxY = max.getBlockY(); + final int maxZ = max.getBlockZ(); for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { @@ -2767,11 +2769,8 @@ public class EditSession { } } - BaseBlock air = new BaseBlock(BlockID.AIR); - - for (int i = 1; i < thickness; ++i) { - final Set newOutside = new HashSet(outside); + final Set newOutside = new HashSet(); outer: for (BlockVector position : region) { for (Vector recurseDirection: recurseDirections) { BlockVector neighbor = position.add(recurseDirection).toBlockVector(); @@ -2783,7 +2782,7 @@ public class EditSession { } } - outside = newOutside; + outside.addAll(newOutside); } outer: for (BlockVector position : region) { @@ -2795,7 +2794,7 @@ public class EditSession { } } - if (setBlock(position, air)) { + if (setBlock(position, pattern.next(position))) { ++affected; } } diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index be1607336..304e05d42 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -394,19 +394,24 @@ public class RegionCommands { @Command( aliases = { "/hollow" }, - usage = "[]", + usage = "[[ ]]", desc = "Hollows out the object contained in this selection", + help = + "Hollows out the object contained in this selection.\n" + + "Optionally fills the hollowed out part with the given block.\n" + + "Thickness is measured in manhattan distance.", min = 0, - max = 1 + max = 2 ) @CommandPermissions("worldedit.region.hollow") @Logging(REGION) public void hollow(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - int thickness = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1; + final int thickness = args.argsLength() >= 1 ? Math.max(1, args.getInteger(0)) : 1; + final Pattern pattern = args.argsLength() >= 2 ? we.getBlockPattern(player, args.getString(1)) : new SingleBlockPattern(new BaseBlock(BlockID.AIR)); - int affected = editSession.hollowOutRegion(session.getSelection(player.getWorld()), thickness); + final int affected = editSession.hollowOutRegion(session.getSelection(player.getWorld()), thickness, pattern); player.print(affected + " block(s) have been changed."); }