From 5f1a014bfbf384060661e9f8bb464533f6215ffb Mon Sep 17 00:00:00 2001 From: sk89q Date: Thu, 14 Oct 2010 02:14:18 -0700 Subject: [PATCH] Added /toggleplace which lets you perform actions that require one point to use position #1 rather than your feet. --- src/WorldEdit.java | 24 +++++++++++++++++++----- src/WorldEditSession.java | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/WorldEdit.java b/src/WorldEdit.java index 640a71bba..3e940dee0 100644 --- a/src/WorldEdit.java +++ b/src/WorldEdit.java @@ -71,6 +71,7 @@ public class WorldEdit { public WorldEdit() { commands.put("/editpos1", "Set editing position #1"); commands.put("/editpos2", "Set editing position #2"); + commands.put("/toggleplace", "Toggle placing at pos #1"); commands.put("/editwand", "Gives you the \"edit wand\""); commands.put("/toggleeditwand", "Toggles edit wand selection"); commands.put("/,", "Toggles super pick axe."); @@ -251,6 +252,16 @@ public class WorldEdit { player.print("Right click = sel. pos 1; double right click = sel. pos 2"); return true; + // Toggle placing at pos #1 + } else if (split[0].equalsIgnoreCase("/toggleplace")) { + checkArgs(split, 0, 0, split[0]); + if (session.togglePlacementPosition()) { + player.print("Now placing at pos #1."); + } else { + player.print("Now placing at the block you stand in."); + } + return true; + // Toggle edit wand } else if (split[0].equalsIgnoreCase("/toggleeditwand")) { checkArgs(split, 0, 0, split[0]); @@ -317,7 +328,7 @@ public class WorldEdit { // Paste } else if (split[0].equalsIgnoreCase("/editpasteair") || split[0].equalsIgnoreCase("/editpaste")) { - Vector pos = player.getBlockIn(); + Vector pos = session.getPlacementPosition(player); session.getClipboard().paste(editSession, pos, split[0].equalsIgnoreCase("/editpaste")); player.findFreePosition(); @@ -332,7 +343,7 @@ public class WorldEdit { int radius = Math.max(1, Integer.parseInt(split[2])); int depth = split.length > 3 ? Math.max(1, Integer.parseInt(split[3])) : 1; - Vector pos = player.getBlockIn(); + Vector pos = session.getPlacementPosition(player); int affected = editSession.fillXZ((int)pos.getX(), (int)pos.getZ(), pos, block, radius, depth); player.print(affected + " block(s) have been created."); @@ -344,7 +355,8 @@ public class WorldEdit { int size = split.length > 1 ? Math.max(1, Integer.parseInt(split[1])) : 1; int height = split.length > 2 ? Math.min(128, Integer.parseInt(split[2]) + 2) : 128; - int affected = editSession.removeAbove(player.getBlockIn(), size, height); + int affected = editSession.removeAbove( + session.getPlacementPosition(player), size, height); player.print(affected + " block(s) have been removed."); return true; @@ -354,7 +366,8 @@ public class WorldEdit { int size = split.length > 1 ? Math.max(1, Integer.parseInt(split[1])) : 1; int height = split.length > 2 ? Math.max(1, Integer.parseInt(split[2])) : 128; - int affected = editSession.removeBelow(player.getBlockIn(), size, height); + int affected = editSession.removeBelow( + session.getPlacementPosition(player), size, height); player.print(affected + " block(s) have been removed."); return true; @@ -451,7 +464,8 @@ public class WorldEdit { } else if(split[0].equalsIgnoreCase("/editdrain")) { checkArgs(split, 1, 1, split[0]); int radius = Math.max(0, Integer.parseInt(split[1])); - int affected = editSession.drainArea(player.getBlockIn(), radius); + int affected = editSession.drainArea( + session.getPlacementPosition(player), radius); player.print(affected + " block(s) have been changed."); return true; diff --git a/src/WorldEditSession.java b/src/WorldEditSession.java index 0acc01b47..b6389eba4 100644 --- a/src/WorldEditSession.java +++ b/src/WorldEditSession.java @@ -28,6 +28,7 @@ import java.util.LinkedList; */ public class WorldEditSession { public static final int MAX_HISTORY_SIZE = 15; + private boolean placeAtPos1 = false; private Vector pos1, pos2; private Region region; private LinkedList history = new LinkedList(); @@ -282,4 +283,26 @@ public class WorldEditSession { superPickAxe = !superPickAxe; return superPickAxe; } + + /** + * @return position + * @throws IncompleteRegionException + */ + public Vector getPlacementPosition(WorldEditPlayer player) + throws IncompleteRegionException { + if (!placeAtPos1) { + return player.getBlockIn(); + } + + checkPos1(); + return pos1; + } + + /** + * Toggle placement position; + */ + public boolean togglePlacementPosition() { + placeAtPos1 = !placeAtPos1; + return placeAtPos1; + } }