From cca5f157f4d0819cf5a6417036819918c6016152 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 25 Oct 2010 01:07:10 -0700 Subject: [PATCH] Clamped Y for //expand and //contract operations. --- src/com/sk89q/worldedit/Vector.java | 11 +++++++++++ src/com/sk89q/worldedit/regions/CuboidRegion.java | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/com/sk89q/worldedit/Vector.java b/src/com/sk89q/worldedit/Vector.java index a9d47cb23..f7126be4d 100644 --- a/src/com/sk89q/worldedit/Vector.java +++ b/src/com/sk89q/worldedit/Vector.java @@ -472,6 +472,17 @@ public class Vector { && getBlockZ() >= min.getBlockZ() && getBlockZ() <= max.getBlockY(); } + /** + * Clamp the Y component. + * + * @param min + * @param max + * @return + */ + public Vector clampY(int min, int max) { + return new Vector(x, Math.max(min, Math.min(max, y)), z); + } + /** * 2D transformation. * diff --git a/src/com/sk89q/worldedit/regions/CuboidRegion.java b/src/com/sk89q/worldedit/regions/CuboidRegion.java index 9b1b59681..97a6c7949 100644 --- a/src/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/src/com/sk89q/worldedit/regions/CuboidRegion.java @@ -168,6 +168,9 @@ public class CuboidRegion implements Region { pos2 = pos2.add(new Vector(0, 0, change.getZ())); } } + + pos1 = pos1.clampY(0, 127); + pos2 = pos2.clampY(0, 127); } /** @@ -217,6 +220,9 @@ public class CuboidRegion implements Region { pos2 = pos2.add(new Vector(0, 0, change.getZ())); } } + + pos1 = pos1.clampY(0, 127); + pos2 = pos2.clampY(0, 127); } /**