From 8e5d2f0dfe7bf817a9e0ab5f4d5d3441c09dae34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Fri, 9 Jul 2021 19:57:59 +0200 Subject: [PATCH] fix mix check --- .../arguments/relative/ArgumentRelativeVec.java | 15 +++++++++++---- .../server/utils/location/RelativeVec.java | 7 +++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/minestom/server/command/builder/arguments/relative/ArgumentRelativeVec.java b/src/main/java/net/minestom/server/command/builder/arguments/relative/ArgumentRelativeVec.java index 76a26fde4..daf251ea9 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/relative/ArgumentRelativeVec.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/relative/ArgumentRelativeVec.java @@ -10,6 +10,8 @@ import org.jetbrains.annotations.NotNull; import java.util.Set; import java.util.function.Function; +import static net.minestom.server.utils.location.RelativeVec.CoordinateType.*; + /** * Common interface for all the relative location arguments. */ @@ -44,7 +46,7 @@ abstract class ArgumentRelativeVec extends Argument { double[] coordinates = new double[split.length]; boolean[] isRelative = new boolean[split.length]; - var type = RelativeVec.CoordinateType.UNDEFINED; + var type = UNDEFINED; for (int i = 0; i < split.length; i++) { final String element = split[i]; try { @@ -52,9 +54,9 @@ abstract class ArgumentRelativeVec extends Argument { if (MODIFIER_CHARS.contains(modifierChar)) { isRelative[i] = true; - if (type == RelativeVec.CoordinateType.UNDEFINED) { - type = modifierChar == LOCAL_CHAR ? RelativeVec.CoordinateType.LOCAL : RelativeVec.CoordinateType.RELATIVE; - } else if (type != (modifierChar == LOCAL_CHAR ? RelativeVec.CoordinateType.LOCAL : RelativeVec.CoordinateType.RELATIVE)) { + if (type == UNDEFINED) { + type = modifierChar == LOCAL_CHAR ? LOCAL : RELATIVE; + } else if (type != (modifierChar == LOCAL_CHAR ? LOCAL : RELATIVE)) { throw new ArgumentSyntaxException("Cannot mix world & local coordinates (everything must either use ^ or not)", input, MIXED_TYPE_ERROR); } @@ -63,6 +65,11 @@ abstract class ArgumentRelativeVec extends Argument { coordinates[i] = getRelativeNumberParser().apply(potentialNumber).doubleValue(); } } else { + if (type == UNDEFINED) { + type = ABSOLUTE; + } else if (type == LOCAL) { + throw new ArgumentSyntaxException("Cannot mix world & local coordinates (everything must either use ^ or not)", input, MIXED_TYPE_ERROR); + } coordinates[i] = getAbsoluteNumberParser().apply(element).doubleValue(); } } catch (NumberFormatException e) { diff --git a/src/main/java/net/minestom/server/utils/location/RelativeVec.java b/src/main/java/net/minestom/server/utils/location/RelativeVec.java index e9a2ddffe..5c9e7652d 100644 --- a/src/main/java/net/minestom/server/utils/location/RelativeVec.java +++ b/src/main/java/net/minestom/server/utils/location/RelativeVec.java @@ -123,11 +123,10 @@ public final class RelativeVec { double double14 = dna11.x() * local.z() + dna12.x() * local.y() + dna13.x() * local.x(); double double16 = dna11.y() * local.z() + dna12.y() * local.y() + dna13.y() * local.x(); double double18 = dna11.z() * local.z() + dna12.z() * local.y() + dna13.z() * local.x(); - return new Vec(double14 + (relativeX ? origin.x() : 0), - double16 + (relativeY ? origin.y() : 0), - double18 + (relativeZ ? origin.z() : 0)); + return new Vec(double14 + origin.x(),double16 + origin.y(),double18 + origin.z()); }), - UNDEFINED((vec, origin, relativeX, relativeY, relativeZ) -> vec); + ABSOLUTE(((vec, origin, relativeX1, relativeY1, relativeZ1) -> vec)), + UNDEFINED((vec, origin, relativeX, relativeY, relativeZ) -> Vec.ZERO); private final CoordinateConverter converter;