From 633f6643a519a765361b20a8cd128b58f906601a Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Mon, 19 Dec 2011 11:58:38 +0100 Subject: [PATCH] Added a thickness parameter to //hollow. --- .../java/com/sk89q/worldedit/EditSession.java | 19 ++++++++++++++++++- .../worldedit/commands/RegionCommands.java | 8 +++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 040be35a0..9e0776f46 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2731,7 +2731,7 @@ public class EditSession { * @return number of blocks affected * @throws MaxChangedBlocksException */ - public int hollowOutRegion(Region region) throws MaxChangedBlocksException { + public int hollowOutRegion(Region region, int thickness) throws MaxChangedBlocksException { int affected = 0; Set outside = new HashSet(); @@ -2769,6 +2769,23 @@ public class EditSession { BaseBlock air = new BaseBlock(BlockID.AIR); + + for (int i = 1; i < thickness; ++i) { + final Set newOutside = new HashSet(outside); + outer: for (BlockVector position : region) { + for (Vector recurseDirection: recurseDirections) { + BlockVector neighbor = position.add(recurseDirection).toBlockVector(); + + if (outside.contains(neighbor)) { + newOutside.add(position); + continue outer; + } + } + } + + outside = newOutside; + } + outer: for (BlockVector position : region) { for (Vector recurseDirection: recurseDirections) { BlockVector neighbor = position.add(recurseDirection).toBlockVector(); diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index 8cc3818aa..be1607336 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -394,17 +394,19 @@ public class RegionCommands { @Command( aliases = { "/hollow" }, - usage = "", + usage = "[]", desc = "Hollows out the object contained in this selection", min = 0, - max = 0 + max = 1 ) @CommandPermissions("worldedit.region.hollow") @Logging(REGION) public void hollow(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - int affected = editSession.hollowOutRegion(session.getSelection(player.getWorld())); + int thickness = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1; + + int affected = editSession.hollowOutRegion(session.getSelection(player.getWorld()), thickness); player.print(affected + " block(s) have been changed."); }