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 f5677ee24..9d54f7315 100644 --- a/src/main/java/net/minestom/server/utils/incubator/Vec.java +++ b/src/main/java/net/minestom/server/utils/incubator/Vec.java @@ -64,21 +64,41 @@ public interface Vec { return with(x() + vec.x(), y() + vec.y(), z() + vec.z()); } + @Contract(pure = true) + default @NotNull Vec add(double value) { + return add(Vec.vec(value)); + } + @Contract(pure = true) default @NotNull Vec sub(@NotNull Vec vec) { return with(x() - vec.x(), y() - vec.y(), z() - vec.z()); } + @Contract(pure = true) + default @NotNull Vec sub(double value) { + return sub(Vec.vec(value)); + } + @Contract(pure = true) default @NotNull Vec mul(@NotNull Vec vec) { return with(x() * vec.x(), y() * vec.y(), z() * vec.z()); } + @Contract(pure = true) + default @NotNull Vec mul(double value) { + return mul(Vec.vec(value)); + } + @Contract(pure = true) default @NotNull Vec div(@NotNull Vec vec) { return with(x() / vec.x(), y() / vec.y(), z() / vec.z()); } + @Contract(pure = true) + default @NotNull Vec div(double value) { + return div(Vec.vec(value)); + } + @Contract(pure = true) default @NotNull Vec neg() { return with(-x(), -y(), -z()); @@ -94,11 +114,21 @@ public interface Vec { return with(Math.min(x(), vec.x()), Math.min(y(), vec.y()), Math.min(z(), vec.z())); } + @Contract(pure = true) + default @NotNull Vec min(double value) { + return min(Vec.vec(value)); + } + @Contract(pure = true) default @NotNull Vec max(@NotNull Vec vec) { return with(Math.max(x(), vec.x()), Math.max(y(), vec.y()), Math.max(z(), vec.z())); } + @Contract(pure = true) + default @NotNull Vec max(double value) { + return max(Vec.vec(value)); + } + @Contract(pure = true) default Vec apply(@NotNull UnaryOperator<@NotNull Vec> operator) { return operator.apply(this); diff --git a/src/test/java/demo/PlayerInit.java b/src/test/java/demo/PlayerInit.java index e2685a93e..92d94d5e9 100644 --- a/src/test/java/demo/PlayerInit.java +++ b/src/test/java/demo/PlayerInit.java @@ -158,7 +158,7 @@ public class PlayerInit { .withZ(operand -> operand + 5) .withY(20) .mul(Vec.vec(5, 5, 5)) - .mul(Vec.vec(5)) + .mul(5) .asBlockPosition(); UnaryOperator blockTransform2 = vec -> Vec.vec(vec.x() * 2, 20, vec.z() + 5); var vec = Vec.ZERO.apply(blockTransform).add(Vec.vec(5));