From d55fa96e3e59274b3182a4bb7fce814e7edad1aa Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 8 Jan 2011 11:40:18 -0800 Subject: [PATCH] Added /thaw. --- src/com/sk89q/worldedit/EditSession.java | 48 +++++++++++++++++++ .../sk89q/worldedit/WorldEditController.java | 11 +++++ 2 files changed, 59 insertions(+) diff --git a/src/com/sk89q/worldedit/EditSession.java b/src/com/sk89q/worldedit/EditSession.java index c081a1c6c..e20049ec5 100755 --- a/src/com/sk89q/worldedit/EditSession.java +++ b/src/com/sk89q/worldedit/EditSession.java @@ -1570,6 +1570,54 @@ public class EditSession { 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. * diff --git a/src/com/sk89q/worldedit/WorldEditController.java b/src/com/sk89q/worldedit/WorldEditController.java index a0744a711..d650617c5 100644 --- a/src/com/sk89q/worldedit/WorldEditController.java +++ b/src/com/sk89q/worldedit/WorldEditController.java @@ -155,6 +155,7 @@ public class WorldEditController { commands.put("/forestgen", " - Make Notch tree forest"); commands.put("/pinegen", " - Make an ugly pine tree forest"); commands.put("/snow", " - Simulate snow cover"); + commands.put("/thaw", " - Unthaw/remove snow"); commands.put("/pumpkins", " - Make a pumpkin forest"); commands.put("/unstuck", "Go up to the first free spot"); commands.put("/ascend", "Go up one level"); @@ -1219,6 +1220,16 @@ public class WorldEditController { 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]);