From 6c33aa44e27b21448e0288cfa1adcc205c5907ae Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 18 Oct 2010 10:45:03 -0700 Subject: [PATCH] Added //walls. --- src/EditSession.java | 37 +++++++++++++++++++++++++++++++++++-- src/WorldEdit.java | 10 ++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/EditSession.java b/src/EditSession.java index a2631bd30..635249c11 100644 --- a/src/EditSession.java +++ b/src/EditSession.java @@ -570,7 +570,7 @@ public class EditSession { /** * Make faces of the region (as if it was a cuboid if it's not). - * + * * @param region * @param block * @return number of blocks affected @@ -582,7 +582,7 @@ public class EditSession { Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); - + for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { if (setBlock(new Vector(x, y, min.getBlockZ()), block)) { affected++; } @@ -608,6 +608,39 @@ public class EditSession { return affected; } + /** + * Make walls of the region (as if it was a cuboid if it's not). + * + * @param region + * @param block + * @return number of blocks affected + * @throws MaxChangedBlocksException + */ + public int makeCuboidWalls(Region region, BaseBlock block) + throws MaxChangedBlocksException { + int affected = 0; + + Vector min = region.getMinimumPoint(); + Vector max = region.getMaximumPoint(); + + for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { + for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { + if (setBlock(new Vector(x, y, min.getBlockZ()), block)) { affected++; } + if (setBlock(new Vector(x, y, max.getBlockZ()), block)) { affected++; } + affected++; + } + } + + for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { + for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { + if (setBlock(new Vector(min.getBlockX(), y, z), block)) { affected++; } + if (setBlock(new Vector(max.getBlockX(), y, z), block)) { affected++; } + } + } + + return affected; + } + /** * Overlays a layer of blocks over a cuboid area. * diff --git a/src/WorldEdit.java b/src/WorldEdit.java index 258bd420a..c65874dc5 100644 --- a/src/WorldEdit.java +++ b/src/WorldEdit.java @@ -123,6 +123,7 @@ public class WorldEdit { commands.put("//size", "Get size of selected region"); commands.put("//set", "[ID] - Set all blocks inside region"); commands.put("//outline", "[ID] - Outline the region with blocks"); + commands.put("//walls", "[ID] - Build walls"); commands.put("//replace", " [ToID] - Replace all existing blocks inside region"); commands.put("//overlay", "[ID] - Overlay the area one layer"); commands.put("/removeabove", " - Remove blocks above head"); @@ -575,6 +576,15 @@ public class WorldEdit { return true; + // Set the walls of a region + } else if(split[0].equalsIgnoreCase("//walls")) { + checkArgs(split, 1, 1, split[0]); + BaseBlock block = getBlock(split[1]); + int affected = editSession.makeCuboidWalls(session.getRegion(), block); + player.print(affected + " block(s) have been changed."); + + return true; + // Drain pools } else if(split[0].equalsIgnoreCase("//drain")) { checkArgs(split, 1, 1, split[0]);