From c218743fa804fcaf490fe8675ae42b74bfdcbf6d Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Mon, 18 Jan 2021 15:37:14 +0000 Subject: [PATCH] Fix some coordinate errors - Fixes WorldGuard weirdness - Fixes #860 --- .../boydti/fawe/object/brush/SplineBrush.java | 8 ++--- .../extent/PositionTransformExtent.java | 2 +- .../com/sk89q/worldedit/math/Vector3.java | 33 ++++++++++++++++--- .../com/sk89q/worldedit/util/Direction.java | 4 +-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index 8fd3fd55a..8097f2104 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -4,7 +4,6 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.mask.IdMask; import com.boydti.fawe.object.visitor.DFSRecursiveVisitor; -import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.brush.Brush; @@ -14,7 +13,6 @@ import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.math.MathUtils; import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.interpolation.Node; @@ -197,15 +195,15 @@ public class SplineBrush implements Brush, ResettableTool { if (det_max == det_x) { double a = (xz * yz - xy * zz) / det_x; double b = (xy * yz - xz * yy) / det_x; - dir = BlockVector3.at(1.0, (int) MathUtils.roundHalfUp(a), (int) MathUtils.roundHalfUp(b)); + dir = BlockVector3.at(1.0, a, b); } else if (det_max == det_y) { double a = (yz * xz - xy * zz) / det_y; double b = (xy * xz - yz * xx) / det_y; - dir = BlockVector3.at((int) MathUtils.roundHalfUp(a), 1.0, (int) MathUtils.roundHalfUp(b)); + dir = BlockVector3.at(a, 1.0, b); } else { double a = (yz * xy - xz * yy) / det_z; double b = (xz * xy - yz * xx) / det_z; - dir = BlockVector3.at((int) MathUtils.roundHalfUp(a), (int) MathUtils.roundHalfUp(b), 1.0); + dir = BlockVector3.at(a, b, 1.0); } return dir.normalize(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java index 17f3215e3..f37f23eee 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java @@ -42,7 +42,7 @@ public class PositionTransformExtent extends ResettableExtent { mutable.mutY(pos.getY() - min.getY()); mutable.mutZ(pos.getZ() - min.getZ()); MutableVector3 tmp = new MutableVector3(transform.apply(mutable.toVector3())); - return min.add(tmp.toBlockPoint()); + return min.add(tmp.roundHalfUp().toBlockPoint()); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java index 09f0387b3..2dd7a9598 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java @@ -83,16 +83,31 @@ public abstract class Vector3 { return YzxOrderComparator.YZX_ORDER; } + /** + * Gets the x coordinate rounded, accounting for negative coordinates + * + * @return the x coordinate + */ public int getBlockX() { - return (int) MathUtils.roundHalfUp(getX()); + return MathMan.roundInt(getX()); } + /** + * Gets the y coordinate rounded, accounting for negative coordinates + * + * @return the y coordinate + */ public int getBlockY() { - return (int) MathUtils.roundHalfUp(getY()); + return MathMan.roundInt(getY()); } + /** + * Gets the z coordinate rounded, accounting for negative coordinates + * + * @return the z coordinate + */ public int getBlockZ() { - return (int) MathUtils.roundHalfUp(getZ()); + return MathMan.roundInt(getZ()); } public MutableVector3 setComponents(Vector3 other) { @@ -487,6 +502,15 @@ public abstract class Vector3 { return Vector3.at(Math.floor(getX() + 0.5), Math.floor(getY() + 0.5), Math.floor(getZ() + 0.5)); } + /** + * Rounds all components using {@link MathUtils#roundHalfUp(double)} + * + * @return a new vector + */ + public Vector3 roundHalfUp() { + return Vector3.at(MathUtils.roundHalfUp(getX()), MathUtils.roundHalfUp(getY()), MathUtils.roundHalfUp(getZ())); + } + /** * Returns a vector with the absolute values of the components of * this vector. @@ -595,8 +619,7 @@ public abstract class Vector3 { * @return a new {@code BlockVector} */ public static BlockVector3 toBlockPoint(double x, double y, double z) { - return BlockVector3.at(MathUtils.roundHalfUp(x), MathUtils.roundHalfUp(y), MathUtils.roundHalfUp(z)); - //return BlockVector3.at(x, y, z); + return BlockVector3.at(x, y, z); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java index 05a29f2ec..35c259f31 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.util; -import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; @@ -80,8 +79,7 @@ public enum Direction { } Direction(Vector3 vector, int flags, int left, int right) { - this.blockPoint = BlockVector3.at(MathMan.roundInt(Math.signum(vector.getX())), - MathMan.roundInt(Math.signum(vector.getY())), MathMan.roundInt(Math.signum(vector.getZ()))); + this.blockPoint = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ())); this.direction = vector.normalize(); this.flags = flags; this.left = left;