Add Coordinate simple impl

This commit is contained in:
TheMode 2021-06-19 22:43:59 +02:00
parent b9114ef5fe
commit 62146352a1
3 changed files with 53 additions and 3 deletions

View File

@ -3,6 +3,13 @@ package net.minestom.server.utils.incubator;
import org.jetbrains.annotations.NotNull;
public interface Coordinate {
Coordinate ZERO = of(0, 0, 0);
static @NotNull Coordinate of(double x, double y, double z) {
return new CoordinateImpl(x, y, z);
}
@NotNull Coordinate with(double x, double y, double z);
default @NotNull Coordinate with(@NotNull Coordinate coordinate) {

View File

@ -0,0 +1,33 @@
package net.minestom.server.utils.incubator;
import org.jetbrains.annotations.NotNull;
class CoordinateImpl implements Coordinate {
private final double x, y, z;
public CoordinateImpl(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public @NotNull Coordinate with(double x, double y, double z) {
return new CoordinateImpl(x, y, z);
}
@Override
public double x() {
return x;
}
@Override
public double y() {
return y;
}
@Override
public double z() {
return z;
}
}

View File

@ -3,18 +3,20 @@ package net.minestom.server.utils.incubator;
import org.jetbrains.annotations.NotNull;
public class Pos implements Coordinate {
private final double x, y, z;
private final float yaw, pitch;
public Pos(double x, double y, double z) {
public Pos(double x, double y, double z, float yaw, float pitch) {
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
}
@Override
public @NotNull Pos with(double x, double y, double z) {
return new Pos(x, y, z);
return new Pos(x, y, z, pitch, yaw);
}
@Override
@ -31,4 +33,12 @@ public class Pos implements Coordinate {
public double z() {
return z;
}
public float yaw() {
return yaw;
}
public float pitch() {
return pitch;
}
}