mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 17:37:42 +01:00
Add Coordinate simple impl
This commit is contained in:
parent
b9114ef5fe
commit
62146352a1
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user