From da4acf79664095c5210120a573e3b1f08a1c7c3c Mon Sep 17 00:00:00 2001 From: TheMode Date: Mon, 5 Jul 2021 08:18:14 +0200 Subject: [PATCH] Deprecate previous coordinate classes --- .../minestom/server/utils/BlockPosition.java | 33 +++++++++++------ .../net/minestom/server/utils/Position.java | 37 ++++++++++++------- .../net/minestom/server/utils/Vector.java | 32 +++++++++++----- .../server/utils/coordinate/Point.java | 9 +++++ 4 files changed, 78 insertions(+), 33 deletions(-) diff --git a/src/main/java/net/minestom/server/utils/BlockPosition.java b/src/main/java/net/minestom/server/utils/BlockPosition.java index 2028fe070..b706f4ab4 100644 --- a/src/main/java/net/minestom/server/utils/BlockPosition.java +++ b/src/main/java/net/minestom/server/utils/BlockPosition.java @@ -1,8 +1,7 @@ package net.minestom.server.utils; -import net.minestom.server.MinecraftServer; import net.minestom.server.instance.block.BlockFace; -import net.minestom.server.utils.clone.PublicCloneable; +import net.minestom.server.utils.coordinate.Point; import org.jetbrains.annotations.NotNull; import java.util.Objects; @@ -11,8 +10,11 @@ import java.util.Objects; /** * Represents the position of a block, so with integers instead of floating numbers. + * + * @deprecated use {@link net.minestom.server.utils.coordinate.Vec} instead */ -public class BlockPosition implements PublicCloneable { +@Deprecated +public class BlockPosition implements Point { private int x, y, z; @@ -212,15 +214,24 @@ public class BlockPosition implements PublicCloneable { MathUtils.square(getZ() - blockPosition.getZ()); } - @NotNull @Override - public BlockPosition clone() { - try { - return (BlockPosition) super.clone(); - } catch (CloneNotSupportedException e) { - MinecraftServer.getExceptionManager().handleException(e); - return null; - } + public double x() { + return x; + } + + @Override + public double y() { + return y; + } + + @Override + public double z() { + return z; + } + + @Override + public @NotNull Point clone() { + return new BlockPosition(x, y, z); } /** diff --git a/src/main/java/net/minestom/server/utils/Position.java b/src/main/java/net/minestom/server/utils/Position.java index 2faf754b7..7bcb7e924 100644 --- a/src/main/java/net/minestom/server/utils/Position.java +++ b/src/main/java/net/minestom/server/utils/Position.java @@ -1,8 +1,7 @@ package net.minestom.server.utils; -import net.minestom.server.MinecraftServer; import net.minestom.server.utils.chunk.ChunkUtils; -import net.minestom.server.utils.clone.PublicCloneable; +import net.minestom.server.utils.coordinate.Point; import org.jetbrains.annotations.NotNull; import java.util.Objects; @@ -10,8 +9,11 @@ import java.util.Objects; /** * Represents a position. * The instance is not contained. + * + * @deprecated use {@link net.minestom.server.utils.coordinate.Pos} instead */ -public class Position implements PublicCloneable { +@Deprecated +public class Position implements Point { private double x, y, z; private float yaw, pitch; @@ -201,15 +203,24 @@ public class Position implements PublicCloneable { this.z = position.getZ(); } - @NotNull @Override - public Position clone() { - try { - return (Position) super.clone(); - } catch (CloneNotSupportedException e) { - MinecraftServer.getExceptionManager().handleException(e); - return null; - } + public double x() { + return x; + } + + @Override + public double y() { + return y; + } + + @Override + public double z() { + return z; + } + + @Override + public @NotNull Position clone() { + return new Position(x, y, z, yaw, pitch); } /** @@ -368,9 +379,9 @@ public class Position implements PublicCloneable { */ private float fixYaw(float yaw) { yaw = yaw % 360; - if(yaw < -180.0F) { + if (yaw < -180.0F) { yaw += 360.0F; - } else if(yaw > 180.0F) { + } else if (yaw > 180.0F) { yaw -= 360.0F; } return yaw; diff --git a/src/main/java/net/minestom/server/utils/Vector.java b/src/main/java/net/minestom/server/utils/Vector.java index 2357e0e92..98ab5880a 100644 --- a/src/main/java/net/minestom/server/utils/Vector.java +++ b/src/main/java/net/minestom/server/utils/Vector.java @@ -2,9 +2,14 @@ package net.minestom.server.utils; import net.minestom.server.MinecraftServer; import net.minestom.server.utils.clone.PublicCloneable; +import net.minestom.server.utils.coordinate.Point; import org.jetbrains.annotations.NotNull; -public class Vector implements PublicCloneable { +/** + * @deprecated use {@link net.minestom.server.utils.coordinate.Vec} instead + */ +@Deprecated +public class Vector implements Point { private static final double epsilon = 0.000001; @@ -484,15 +489,24 @@ public class Vector implements PublicCloneable { '}'; } - @NotNull @Override - public Vector clone() { - try { - return (Vector) super.clone(); - } catch (CloneNotSupportedException e) { - MinecraftServer.getExceptionManager().handleException(e); - throw new IllegalStateException("Weird thing happened"); - } + public double x() { + return x; + } + + @Override + public double y() { + return y; + } + + @Override + public double z() { + return z; + } + + @Override + public @NotNull Vector clone() { + return new Vector(x,y,z); } public double getX() { diff --git a/src/main/java/net/minestom/server/utils/coordinate/Point.java b/src/main/java/net/minestom/server/utils/coordinate/Point.java index 2a23b5bc6..5432f4336 100644 --- a/src/main/java/net/minestom/server/utils/coordinate/Point.java +++ b/src/main/java/net/minestom/server/utils/coordinate/Point.java @@ -80,4 +80,13 @@ public interface Point { (y() == castedY) ? castedY : castedY + 1, (int) Math.floor(z())); } + + /** + * @deprecated present for backward compatibility + */ + @Deprecated + @Contract(pure = true) + default @NotNull Point clone() { + return this; + } }