From 1b88e1592e4f5140821311d61a72ebc818f06326 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 18 Oct 2010 10:39:32 -0700 Subject: [PATCH] Added //sphere and //hsphere. --- src/EditSession.java | 37 +++++++++++++++++++++++++++++++++++++ src/WorldEdit.java | 25 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/EditSession.java b/src/EditSession.java index a5a7361f0..a2631bd30 100644 --- a/src/EditSession.java +++ b/src/EditSession.java @@ -1005,6 +1005,43 @@ public class EditSession { return affected; } + /** + * Makes a sphere. + * + * @param pos + * @param block + * @param radius + * @param filled + * @return number of blocks changed + * @throws MaxChangedBlocksException + */ + public int makeSphere(Vector pos, BaseBlock block, int radius, boolean filled) + throws MaxChangedBlocksException { + int affected = 0; + + for (int x = 0; x <= radius; x++) { + for (int y = 0; y <= radius; y++) { + for (int z = 0; z <= radius; z++) { + Vector vec = pos.add(x, y, z); + double d = vec.distance(pos); + + if (d <= radius + 0.5 && (filled || d >= radius - 0.5)) { + if (setBlock(vec, block)) { affected++; } + if (setBlock(pos.add(-x, y, z), block)) { affected++; } + if (setBlock(pos.add(x, -y, z), block)) { affected++; } + if (setBlock(pos.add(x, y, -z), block)) { affected++; } + if (setBlock(pos.add(-x, -y, z), block)) { affected++; } + if (setBlock(pos.add(x, -y, -z), block)) { affected++; } + if (setBlock(pos.add(-x, y, -z), block)) { affected++; } + if (setBlock(pos.add(-x, -y, -z), block)) { affected++; } + } + } + } + } + + return affected; + } + /** * Set a block by chance. diff --git a/src/WorldEdit.java b/src/WorldEdit.java index 565a738ad..70855cbb9 100644 --- a/src/WorldEdit.java +++ b/src/WorldEdit.java @@ -143,6 +143,8 @@ public class WorldEdit { commands.put("//rotate", "[Angle] - Rotate the clipboard"); commands.put("//hcyl", "[ID] [Radius] - Create a vertical hollow cylinder"); commands.put("//cyl", "[ID] [Radius] - Create a vertical cylinder"); + commands.put("//sphere", "[ID] [Radius] [Raised?] - Create a sphere"); + commands.put("//hsphere", "[ID] [Radius] [Raised?] - Create a hollow sphere"); commands.put("/fixwater", "[Radius] - Level nearby pools of water"); commands.put("/forestgen", " - Make an ugly pine tree forest"); commands.put("/unstuck", "Go up to the first free spot"); @@ -433,6 +435,29 @@ public class WorldEdit { return true; + // Draw a sphere + } else if (split[0].equalsIgnoreCase("//sphere") + || split[0].equalsIgnoreCase("//hsphere")) { + checkArgs(split, 2, 3, split[0]); + BaseBlock block = getBlock(split[1]); + int radius = Math.max(1, Integer.parseInt(split[2])); + boolean raised = split.length > 3 + ? (split[3].equalsIgnoreCase("true") + || split[3].equalsIgnoreCase("yes")) + : false; + boolean filled = split[0].equalsIgnoreCase("//sphere"); + + Vector pos = session.getPlacementPosition(player); + if (raised) { + pos = pos.add(0, radius, 0); + } + + int affected = editSession.makeSphere(pos, block, radius, filled); + player.findFreePosition(); + player.print(affected + " block(s) have been created."); + + return true; + // Fill a hole } else if (split[0].equalsIgnoreCase("//fill")) { checkArgs(split, 2, 3, split[0]);