Skip to content

Commit

Permalink
Added /thaw.
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Jan 8, 2011
1 parent 1767597 commit d55fa96
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/com/sk89q/worldedit/EditSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,54 @@ public int makeSphere(Vector pos, BaseBlock block, int radius,
return affected;
}

/**
* Thaw.
*
* @param pos
* @param radius
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int thaw(Vector pos, int radius)
throws MaxChangedBlocksException {
int affected = 0;
int radiusSq = (int)Math.pow(radius, 2);

int ox = pos.getBlockX();
int oy = pos.getBlockY();
int oz = pos.getBlockZ();

BaseBlock air = new BaseBlock(0);
BaseBlock water = new BaseBlock(BlockID.STATIONARY_WATER);

for (int x = ox - radius; x <= ox + radius; x++) {
for (int z = oz - radius; z <= oz + radius; z++) {
if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) {
continue;
}

for (int y = 127; y >= 1; y--) {
Vector pt = new Vector(x, y, z);
int id = getBlock(pt).getID();

if (id == BlockID.ICE) { // Ice
if (setBlock(pt, water)) {
affected++;
}
} else if (id == BlockID.SNOW) {
if (setBlock(pt, air)) {
affected++;
}
} else if (id != 0) {
break;
}
}
}
}

return affected;
}

/**
* Make snow.
*
Expand Down
11 changes: 11 additions & 0 deletions src/com/sk89q/worldedit/WorldEditController.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public WorldEditController(ServerInterface server, LocalConfiguration config) {
commands.put("/forestgen", "<Size> <Density> - Make Notch tree forest");
commands.put("/pinegen", "<Size> <Density> - Make an ugly pine tree forest");
commands.put("/snow", "<Radius> - Simulate snow cover");
commands.put("/thaw", "<Radius> - Unthaw/remove snow");
commands.put("/pumpkins", "<Size> - Make a pumpkin forest");
commands.put("/unstuck", "Go up to the first free spot");
commands.put("/ascend", "Go up one level");
Expand Down Expand Up @@ -1219,6 +1220,16 @@ public boolean performCommand(LocalPlayer player,

return true;

// Thaw
} else if (split[0].equalsIgnoreCase("/thaw")) {
checkArgs(split, 0, 1, split[0]);
int size = split.length > 1 ? Math.max(1, Integer.parseInt(split[1])) : 10;

int affected = editSession.thaw(player.getBlockIn(), size);
player.print(affected + " surfaces thawed.");

return true;

// Make pumpkin patches
} else if (split[0].equalsIgnoreCase("/pumpkins")) {
checkArgs(split, 0, 1, split[0]);
Expand Down

0 comments on commit d55fa96

Please sign in to comment.