From 06f9284df16032e7c983cf8e091c82916f48657a Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 6 Nov 2010 21:26:52 -0700 Subject: [PATCH] Added /snow. --- src/EditSession.java | 81 ++++++++++++++++++++++++++++++++++++++ src/WorldEditListener.java | 11 ++++++ 2 files changed, 92 insertions(+) diff --git a/src/EditSession.java b/src/EditSession.java index 44ac76fcb..465faa20b 100644 --- a/src/EditSession.java +++ b/src/EditSession.java @@ -1258,6 +1258,87 @@ public class EditSession { return affected; } + /** + * Make snow. + * + * @param pos + * @param radius + * @return number of blocks affected + * @throws MaxChangedBlocksException + */ + public int simulateSnow(Vector pos, int radius) + throws MaxChangedBlocksException { + int affected = 0; + + int ox = pos.getBlockX(); + int oy = pos.getBlockY(); + int oz = pos.getBlockZ(); + + BaseBlock ice = new BaseBlock(79); + BaseBlock snow = new BaseBlock(78); + + for (int x = ox - radius; x <= ox + radius; x++) { + for (int z = oz - radius; z <= oz + radius; z++) { + if ((new Vector(x, oy, z)).distance(pos) > radius) { + continue; + } + + for (int y = 127; y >= 1; y--) { + Vector pt = new Vector(x, y, z); + int id = getBlock(pt).getID(); + + // Snow should not cover these blocks + if (id == 6 // Saplings + || id == 10 // Lava + || id == 11 // Lava + || id == 37 // Yellow flower + || id == 38 // Red rose + || id == 39 // Brown mushroom + || id == 40 // Red mushroom + || id == 44 // Step + || id == 50 // Torch + || id == 51 // Fire + || id == 53 // Wood steps + || id == 55 // Redstone wire + || id == 59 // Crops + || (id >= 63 && id <= 72) + || id == 75 // Redstone torch + || id == 76 // Redstone torch + || id == 77 // Stone button + || id == 78 // Snow + || id == 79 // Ice + || id == 81 // Cactus + || id == 83 // Reed + || id == 85 // Fence + || id == 90) { // Portal + break; + } + + // Ice! + if (id == 8 || id == 9) { + if (setBlock(pt, ice)) { + affected++; + } + break; + } + + // Cover + if (id != 0) { + if (y == 127) { // Too high! + break; + } + + if (setBlock(pt.add(0, 1, 0), snow)) { + affected++; + } + break; + } + } + } + } + + return affected; + } /** * Set a block by chance. diff --git a/src/WorldEditListener.java b/src/WorldEditListener.java index 1431f2798..5de445c2b 100644 --- a/src/WorldEditListener.java +++ b/src/WorldEditListener.java @@ -161,6 +161,7 @@ public class WorldEditListener extends PluginListener { commands.put("/ex", "[Size] - Extinguish fires"); commands.put("/forestgen", " - Make Notch tree forest"); commands.put("/pinegen", " - Make an ugly pine tree forest"); + commands.put("/snow", " - Simulate snow cover"); commands.put("/pumpkins", " - Make a pumpkin forest"); commands.put("/unstuck", "Go up to the first free spot"); commands.put("/ascend", "Go up one level"); @@ -917,6 +918,16 @@ public class WorldEditListener extends PluginListener { return true; + // Let it snow~ + } else if (split[0].equalsIgnoreCase("/snow")) { + checkArgs(split, 0, 1, split[0]); + int size = split.length > 1 ? Math.max(1, Integer.parseInt(split[1])) : 10; + + int affected = editSession.simulateSnow(player.getBlockIn(), size); + player.print(affected + " surfaces covered. Let it snow~"); + + return true; + // Make pumpkin patches } else if (split[0].equalsIgnoreCase("/pumpkins")) { checkArgs(split, 0, 1, split[0]);