mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Add comments
This commit is contained in:
parent
cd090e13d0
commit
a9e78d5583
@ -42,36 +42,87 @@ public interface Point {
|
|||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
double z();
|
double z();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the floored value of the X component
|
||||||
|
*
|
||||||
|
* @return the block X
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
default int blockX() {
|
default int blockX() {
|
||||||
return MathUtils.floor(x());
|
return MathUtils.floor(x());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the floored value of the X component
|
||||||
|
*
|
||||||
|
* @return the block X
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
default int blockY() {
|
default int blockY() {
|
||||||
return MathUtils.floor(y());
|
return MathUtils.floor(y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the floored value of the X component
|
||||||
|
*
|
||||||
|
* @return the block X
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
default int blockZ() {
|
default int blockZ() {
|
||||||
return MathUtils.floor(z());
|
return MathUtils.floor(z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a point with a modified X coordinate based on its value.
|
||||||
|
*
|
||||||
|
* @param operator the operator providing the current X coordinate and returning the new
|
||||||
|
* @return a new point
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull Point withX(@NotNull DoubleUnaryOperator operator);
|
@NotNull Point withX(@NotNull DoubleUnaryOperator operator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a point with the specified X coordinate.
|
||||||
|
*
|
||||||
|
* @param x the new X coordinate
|
||||||
|
* @return a new point
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull Point withX(double x);
|
@NotNull Point withX(double x);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a point with a modified Y coordinate based on its value.
|
||||||
|
*
|
||||||
|
* @param operator the operator providing the current Y coordinate and returning the new
|
||||||
|
* @return a new point
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull Point withY(@NotNull DoubleUnaryOperator operator);
|
@NotNull Point withY(@NotNull DoubleUnaryOperator operator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a point with the specified Y coordinate.
|
||||||
|
*
|
||||||
|
* @param y the new Y coordinate
|
||||||
|
* @return a new point
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull Point withY(double y);
|
@NotNull Point withY(double y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a point with a modified Z coordinate based on its value.
|
||||||
|
*
|
||||||
|
* @param operator the operator providing the current Z coordinate and returning the new
|
||||||
|
* @return a new point
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull Point withZ(@NotNull DoubleUnaryOperator operator);
|
@NotNull Point withZ(@NotNull DoubleUnaryOperator operator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a point with the specified Z coordinate.
|
||||||
|
*
|
||||||
|
* @param z the new Z coordinate
|
||||||
|
* @return a new point
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
@NotNull Point withZ(double z);
|
@NotNull Point withZ(double z);
|
||||||
|
|
||||||
@ -126,8 +177,9 @@ public interface Point {
|
|||||||
return sub(1, 0, 0);
|
return sub(1, 0, 0);
|
||||||
case EAST:
|
case EAST:
|
||||||
return add(1, 0, 0);
|
return add(1, 0, 0);
|
||||||
|
default: // should never be called
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
return this; // should never be called
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,6 +224,12 @@ public interface Point {
|
|||||||
Double.compare(point.z(), z()) == 0;
|
Double.compare(point.z(), z()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the three coordinates {@link #x()}, {@link #y()} and {@link #z()}
|
||||||
|
* are equals to {@code 0}.
|
||||||
|
*
|
||||||
|
* @return true if the three coordinates are zero
|
||||||
|
*/
|
||||||
default boolean isZero() {
|
default boolean isZero() {
|
||||||
return x() == 0 && y() == 0 && z() == 0;
|
return x() == 0 && y() == 0 && z() == 0;
|
||||||
}
|
}
|
||||||
@ -180,7 +238,7 @@ public interface Point {
|
|||||||
* Gets if two points are in the same chunk.
|
* Gets if two points are in the same chunk.
|
||||||
*
|
*
|
||||||
* @param point the point to compare two
|
* @param point the point to compare two
|
||||||
* @return true if 'this' is in the same chunk as {@code position}
|
* @return true if 'this' is in the same chunk as {@code point}
|
||||||
*/
|
*/
|
||||||
default boolean inSameChunk(@NotNull Point point) {
|
default boolean inSameChunk(@NotNull Point point) {
|
||||||
return ChunkUtils.getChunkCoordinate(x()) == ChunkUtils.getChunkCoordinate(point.x()) &&
|
return ChunkUtils.getChunkCoordinate(x()) == ChunkUtils.getChunkCoordinate(point.x()) &&
|
||||||
|
@ -2,7 +2,6 @@ package net.minestom.server.coordinate;
|
|||||||
|
|
||||||
import net.minestom.server.instance.block.BlockFace;
|
import net.minestom.server.instance.block.BlockFace;
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
import net.minestom.server.utils.Position;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -40,12 +39,27 @@ public final class Pos implements Point {
|
|||||||
this(point, 0, 0);
|
this(point, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a {@link Point} into a {@link Pos}.
|
||||||
|
* Will cast if possible, or instantiate a new object.
|
||||||
|
*
|
||||||
|
* @param point the point to convert
|
||||||
|
* @return the converted position
|
||||||
|
*/
|
||||||
public static @NotNull Pos fromPoint(@NotNull Point point) {
|
public static @NotNull Pos fromPoint(@NotNull Point point) {
|
||||||
if (point instanceof Pos)
|
if (point instanceof Pos)
|
||||||
return (Pos) point;
|
return (Pos) point;
|
||||||
return new Pos(point.x(), point.y(), point.z());
|
return new Pos(point.x(), point.y(), point.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the 3 coordinates of this position.
|
||||||
|
*
|
||||||
|
* @param x the X coordinate
|
||||||
|
* @param y the Y coordinate
|
||||||
|
* @param z the Z coordinate
|
||||||
|
* @return a new position
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
public @NotNull Pos withCoord(double x, double y, double z) {
|
public @NotNull Pos withCoord(double x, double y, double z) {
|
||||||
return new Pos(x, y, z, yaw, pitch);
|
return new Pos(x, y, z, yaw, pitch);
|
||||||
@ -152,9 +166,15 @@ public final class Pos implements Point {
|
|||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new position based on this position fields.
|
||||||
|
*
|
||||||
|
* @param operator the operator deconstructing this object and providing a new position
|
||||||
|
* @return the new position
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
public @NotNull Pos with(@NotNull Operator operator) {
|
public @NotNull Pos apply(@NotNull Operator operator) {
|
||||||
return operator.apply(x, y, z);
|
return operator.apply(x, y, z, yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -303,6 +323,6 @@ public final class Pos implements Point {
|
|||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Operator {
|
public interface Operator {
|
||||||
@NotNull Pos apply(double x, double y, double z);
|
@NotNull Pos apply(double x, double y, double z, float yaw, float pitch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user