From ccab458d9c525655f6cfcac2916708e222e8dee8 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 18 Oct 2010 16:36:22 -0700 Subject: [PATCH] Added /removenear. --- src/EditSession.java | 30 ++++++++++++++++++++++++++++++ src/WorldEdit.java | 13 +++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/EditSession.java b/src/EditSession.java index a00d431b5..c821d32c7 100644 --- a/src/EditSession.java +++ b/src/EditSession.java @@ -481,6 +481,36 @@ public class EditSession { return affected; } + /** + * Remove nearby blocks of a type. + * + * @param pos + * @param blockType + * @param size + * @return number of blocks affected + */ + public int removeNear(Vector pos, int blockType, int size) throws + MaxChangedBlocksException { + int affected = 0; + BaseBlock air = new BaseBlock(0); + + for (int x = -size; x <= size; x++) { + for (int y = -size; y <= size; y++) { + for (int z = -size; z <= size; z++) { + Vector p = pos.add(x, y, z); + + if (getBlock(p).getID() == blockType) { + if (setBlock(p, air)) { + affected++; + } + } + } + } + } + + return affected; + } + /** * Sets all the blocks inside a region to a certain block type. * diff --git a/src/WorldEdit.java b/src/WorldEdit.java index 62c52b393..3f1921362 100644 --- a/src/WorldEdit.java +++ b/src/WorldEdit.java @@ -130,6 +130,7 @@ public class WorldEdit { commands.put("//overlay", "[ID] - Overlay the area one layer"); commands.put("/removeabove", " - Remove blocks above head"); commands.put("/removebelow", " - Remove blocks below position"); + commands.put("/removenear", " - Remove blocks near you"); commands.put("//copy", "Copies the currently selected region"); commands.put("//cut", "Cuts the currently selected region"); commands.put("//paste", "Pastes the clipboard"); @@ -492,6 +493,18 @@ public class WorldEdit { return true; + // Remove blocks near + } else if (split[0].equalsIgnoreCase("/removenear")) { + checkArgs(split, 2, 2, split[0]); + BaseBlock block = getBlock(split[1]); + int size = Math.max(1, Integer.parseInt(split[2])); + + int affected = editSession.removeNear( + session.getPlacementPosition(player), block.getID(), size); + player.print(affected + " block(s) have been removed."); + + return true; + // Load .schematic to clipboard } else if (split[0].equalsIgnoreCase("//load")) { checkArgs(split, 1, 1, split[0]);