Added //sphere and //hsphere.

This commit is contained in:
sk89q 2010-10-18 10:39:32 -07:00
parent 3ad6577be6
commit 1b88e1592e
2 changed files with 62 additions and 0 deletions

View File

@ -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.

View File

@ -143,6 +143,8 @@ public class WorldEdit {
commands.put("//rotate", "[Angle] - Rotate the clipboard");
commands.put("//hcyl", "[ID] [Radius] <Height> - Create a vertical hollow cylinder");
commands.put("//cyl", "[ID] [Radius] <Height> - 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", "<Size> - 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]);