Pos improvements

This commit is contained in:
TheMode 2021-06-20 18:27:58 +02:00
parent ab9e16dfe7
commit 602472fc65
2 changed files with 31 additions and 0 deletions

View File

@ -1,8 +1,11 @@
package net.minestom.server.utils.incubator;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
public class Pos implements Vec {
public static final Pos ZERO = new Pos();
private final double x, y, z;
private final float yaw, pitch;
@ -14,6 +17,24 @@ public class Pos implements Vec {
this.pitch = pitch;
}
public Pos(double x, double y, double z) {
this(x, y, z, 0, 0);
}
public Pos() {
this(0, 0, 0, 0, 0);
}
@Contract(pure = true)
public @NotNull Pos withYaw(float yaw) {
return new Pos(x, y, z, yaw, pitch);
}
@Contract(pure = true)
public @NotNull Pos withPitch(float pitch) {
return new Pos(x, y, z, yaw, pitch);
}
@Override
public @NotNull Pos with(double x, double y, double z) {
return new Pos(x, y, z, pitch, yaw);
@ -41,4 +62,9 @@ public class Pos implements Vec {
public float pitch() {
return pitch;
}
@Override
public @NotNull Pos asPosition() {
return this;
}
}

View File

@ -82,6 +82,11 @@ public interface Vec {
return operator.apply(this);
}
@Contract(pure = true)
default @NotNull Pos asPosition() {
return new Pos(x(), y(), z());
}
@Contract(pure = true)
double x();