From 363372b16070fc0fd5618d374bf177abfaab7c8a Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 6 Nov 2010 21:47:50 -0700 Subject: [PATCH] Added /up. --- src/WorldEditListener.java | 13 ++++++++ src/WorldEditPlayer.java | 32 +++++++++++++++++++ src/com/sk89q/worldedit/blocks/BlockType.java | 32 +++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/src/WorldEditListener.java b/src/WorldEditListener.java index 5de445c2b..6ff1a65cb 100644 --- a/src/WorldEditListener.java +++ b/src/WorldEditListener.java @@ -169,6 +169,7 @@ public class WorldEditListener extends PluginListener { commands.put("/jumpto", "Jump to the block that you are looking at"); commands.put("/thru", "Go through the wall that you are looking at"); commands.put("/ceil", " - Get to the ceiling"); + commands.put("/up", " - Go up some distance"); commands.put("/chunkinfo", "Get the filename of the chunk that you are in"); commands.put("/listchunks", "Print a list of used chunks"); commands.put("/delchunks", "Generate a shell script to delete chunks"); @@ -442,6 +443,18 @@ public class WorldEditListener extends PluginListener { } return true; + // Go up + } else if (split[0].equalsIgnoreCase("/up")) { + checkArgs(split, 1, 1, split[0]); + int distance = Integer.parseInt(split[1]); + + if (player.ascendUpwards(distance)) { + player.print("Whoosh!"); + } else { + player.printError("You would hit something above you."); + } + return true; + // Set edit position #1 } else if (split[0].equalsIgnoreCase("//pos1")) { checkArgs(split, 0, 0, split[0]); diff --git a/src/WorldEditPlayer.java b/src/WorldEditPlayer.java index bad346e96..50fe5dfb6 100644 --- a/src/WorldEditPlayer.java +++ b/src/WorldEditPlayer.java @@ -225,6 +225,38 @@ public class WorldEditPlayer { return false; } + /** + * Just go up. + * + * @param distance + * @return whether the player was moved + */ + public boolean ascendUpwards(int distance) { + Vector pos = getBlockIn(); + int x = pos.getBlockX(); + int initialY = Math.max(0, pos.getBlockY()); + int y = Math.max(0, pos.getBlockY() + 1); + int z = pos.getBlockZ(); + int maxY = Math.min(128, initialY + distance); + + while (y <= 129) { + if (!BlockType.canPassThrough(ServerInterface.getBlockType(new Vector(x, y, z)))) { + break; // Hit something + } else if (y > maxY + 1) { + break; + } else if (y == maxY + 1) { + ServerInterface.setBlockType(new Vector(x, y - 2, z), + BlockType.GLASS.getID()); + setPosition(new Vector(x + 0.5, y - 1, z + 0.5)); + return true; + } + + y++; + } + + return false; + } + /** * Returns true if equal. * diff --git a/src/com/sk89q/worldedit/blocks/BlockType.java b/src/com/sk89q/worldedit/blocks/BlockType.java index 85f966e5e..befa1048b 100644 --- a/src/com/sk89q/worldedit/blocks/BlockType.java +++ b/src/com/sk89q/worldedit/blocks/BlockType.java @@ -236,4 +236,36 @@ public enum BlockType { || id == 83 // Reed || id == 90; // Portal } + + /** + * Checks whether a block can be passed through. + * + * @param id + * @return + */ + public static boolean canPassThrough(int id) { + return id == 0 // Air + || id == 6 // Saplings + || id == 37 // Yellow flower + || id == 38 // Red flower + || id == 39 // Brown mushroom + || id == 40 // Red mush room + || id == 50 // Torch + || id == 51 // Fire + || id == 55 // Redstone wire + || id == 59 // Crops + || id == 63 // Sign post + || id == 65 // Ladder + || id == 66 // Minecart tracks + || id == 68 // Wall sign + || id == 69 // Lever + || id == 70 // Stone pressure plate + || id == 72 // Wooden pressure plate + || id == 75 // Redstone torch (off) + || id == 76 // Redstone torch (on) + || id == 77 // Stone button + || id == 78 // Snow + || id == 83 // Reed + || id == 90; // Portal + } } \ No newline at end of file