mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-16 23:55:14 +01:00
Add shortcuts for math with a single value vector
This commit is contained in:
parent
95e69c6f53
commit
c42b494a62
@ -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);
|
||||
|
@ -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<Vec> blockTransform2 = vec -> Vec.vec(vec.x() * 2, 20, vec.z() + 5);
|
||||
var vec = Vec.ZERO.apply(blockTransform).add(Vec.vec(5));
|
||||
|
Loading…
Reference in New Issue
Block a user