Skip to content

Commit

Permalink
Added /removenear.
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Oct 18, 2010
1 parent 9487619 commit ccab458
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/EditSession.java
Expand Up @@ -481,6 +481,36 @@ public int removeBelow(Vector pos, int size, int height) throws
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.
*
Expand Down
13 changes: 13 additions & 0 deletions src/WorldEdit.java
Expand Up @@ -130,6 +130,7 @@ private WorldEdit() {
commands.put("//overlay", "[ID] - Overlay the area one layer");
commands.put("/removeabove", "<Size> <Height> - Remove blocks above head");
commands.put("/removebelow", "<Size> <Height> - Remove blocks below position");
commands.put("/removenear", "<ID> <Size> - 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");
Expand Down Expand Up @@ -492,6 +493,18 @@ public boolean performCommand(WorldEditPlayer player,

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]);
Expand Down

0 comments on commit ccab458

Please sign in to comment.