diff --git a/src/main/java/net/minestom/server/utils/incubator/Point.java b/src/main/java/net/minestom/server/utils/incubator/Point.java index c4e506db8..9e59d4b3d 100644 --- a/src/main/java/net/minestom/server/utils/incubator/Point.java +++ b/src/main/java/net/minestom/server/utils/incubator/Point.java @@ -40,7 +40,7 @@ public interface Point { @Contract(pure = true) default @NotNull Point asBlockPosition() { final int castedY = (int) y(); - return Vec.vec((int) Math.floor(x()), + return new Vec((int) Math.floor(x()), (y() == castedY) ? castedY : castedY + 1, (int) Math.floor(z())); } diff --git a/src/main/java/net/minestom/server/utils/incubator/Pos.java b/src/main/java/net/minestom/server/utils/incubator/Pos.java index 8dc9b60f1..e002279f4 100644 --- a/src/main/java/net/minestom/server/utils/incubator/Pos.java +++ b/src/main/java/net/minestom/server/utils/incubator/Pos.java @@ -9,7 +9,7 @@ public final class Pos implements Point { private final double x, y, z; private final float yaw, pitch; - private Pos(double x, double y, double z, float yaw, float pitch) { + public Pos(double x, double y, double z, float yaw, float pitch) { this.x = x; this.y = y; this.z = z; @@ -17,24 +17,16 @@ public final class Pos implements Point { this.pitch = pitch; } - @Contract(pure = true) - static @NotNull Pos pos(double x, double y, double z, float yaw, float pitch) { - return new Pos(x, y, z, yaw, pitch); + public Pos(double x, double y, double z) { + this(x, y, z, 0, 0); } - @Contract(pure = true) - static @NotNull Pos pos(@NotNull Vec vec, float yaw, float pitch) { - return pos(vec.x(), vec.y(), vec.z(), yaw, pitch); + public Pos(@NotNull Vec vec, float yaw, float pitch) { + this(vec.x(), vec.y(), vec.z(), yaw, pitch); } - @Contract(pure = true) - static @NotNull Pos pos(double x, double y, double z) { - return new Pos(x, y, z, 0, 0); - } - - @Contract(pure = true) - static @NotNull Pos pos(@NotNull Vec vec) { - return pos(vec.x(), vec.y(), vec.z()); + public Pos(@NotNull Vec vec) { + this(vec.x(), vec.y(), vec.z(), 0, 0); } @Contract(pure = true) @@ -99,6 +91,6 @@ public final class Pos implements Point { @Contract(pure = true) public @NotNull Vec asVec() { - return Vec.vec(x, y, z); + return new Vec(x, y, z); } } diff --git a/src/main/java/net/minestom/server/utils/incubator/Vec.java b/src/main/java/net/minestom/server/utils/incubator/Vec.java index 53439e4ab..ce42006bc 100644 --- a/src/main/java/net/minestom/server/utils/incubator/Vec.java +++ b/src/main/java/net/minestom/server/utils/incubator/Vec.java @@ -12,28 +12,22 @@ import java.util.function.UnaryOperator; * Represents an immutable 3D vector. */ public final class Vec implements Point { - public static final Vec ZERO = vec(0); - public static final Vec ONE = vec(1); + public static final Vec ZERO = new Vec(0); + public static final Vec ONE = new Vec(1); private final double x, y, z; - private Vec(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - /** * Creates a new vec with the 3 coordinates set. * * @param x the X coordinate * @param y the Y coordinate * @param z the Z coordinate - * @return the created vec */ - @Contract(pure = true) - public static @NotNull Vec vec(double x, double y, double z) { - return new Vec(x, y, z); + public Vec(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; } /** @@ -41,22 +35,18 @@ public final class Vec implements Point { * * @param x the X coordinate * @param z the Z coordinate - * @return the created vec */ - @Contract(pure = true) - public static @NotNull Vec vec(double x, double z) { - return new Vec(x, 0, z); + public Vec(double x, double z) { + this(x, 0, z); } /** * Creates a vec with all 3 coordinates sharing the same value. * * @param value the coordinates - * @return the created vec */ - @Contract(pure = true) - public static @NotNull Vec vec(double value) { - return new Vec(value, value, value); + public Vec(double value) { + this(value, value, value); } /** @@ -177,7 +167,7 @@ public final class Vec implements Point { @Contract(pure = true) public @NotNull Pos asPosition() { - return Pos.pos(this); + return new Pos(x, y, z); } /** diff --git a/src/test/java/demo/PlayerInit.java b/src/test/java/demo/PlayerInit.java index 37bff147f..b4e15b9ba 100644 --- a/src/test/java/demo/PlayerInit.java +++ b/src/test/java/demo/PlayerInit.java @@ -157,11 +157,11 @@ public class PlayerInit { UnaryOperator blockTransform = vec -> vec.withX(x -> x * 2) .withZ(operand -> operand + 5) .withY(20) - .mul(Vec.vec(5, 5, 5)) + .mul(new Vec(5)) .mul(5); - UnaryOperator blockTransform2 = vec -> Vec.vec(vec.x() * 2, 20, vec.z() + 5); - var vec = Vec.ZERO.apply(blockTransform).add(Vec.vec(5)); - var vec2 = Vec.ZERO.with((x, y, z) -> Vec.vec(x + 5, y / 5, z * 5)); + UnaryOperator blockTransform2 = vec -> new Vec(vec.x() * 2, 20, vec.z() + 5); + var vec = Vec.ZERO.apply(blockTransform).add(new Vec(5)); + var vec2 = Vec.ZERO.with((x, y, z) -> new Vec(x + 5, y / 5, z * 5)); var eventHandler = MinecraftServer.getGlobalEventHandler(); eventHandler.addChild(DEMO_NODE); var children = eventHandler.findChildren("demo", Event.class);