diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java index 344f6a0132..2832bd98ca 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java @@ -26,7 +26,7 @@ /** * An immutable 2-dimensional vector. */ -public final class BlockVector2 { +public record BlockVector2(int x, int z) { public static final BlockVector2 ZERO = new BlockVector2(0, 0); public static final BlockVector2 UNIT_X = new BlockVector2(1, 0); @@ -74,25 +74,13 @@ public static BlockVector2 at(int x, int z) { return new BlockVector2(x, z); } - private final int x; - private final int z; - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param z the Z coordinate - */ - private BlockVector2(int x, int z) { - this.x = x; - this.z = z; - } - /** * Get the X coordinate. * * @return the x coordinate + * @deprecated use {@link #x()} instead */ + @Deprecated(forRemoval = true) public int getX() { return x; } @@ -101,7 +89,9 @@ public int getX() { * Get the X coordinate. * * @return the x coordinate + * @deprecated use {@link #x()} instead */ + @Deprecated(forRemoval = true) public int getBlockX() { return x; } @@ -120,7 +110,9 @@ public BlockVector2 withX(int x) { * Get the Z coordinate. * * @return the z coordinate + * @deprecated use {@link #z()} instead */ + @Deprecated(forRemoval = true) public int getZ() { return z; } @@ -129,7 +121,9 @@ public int getZ() { * Get the Z coordinate. * * @return the z coordinate + * @deprecated use {@link #z()} instead */ + @Deprecated(forRemoval = true) public int getBlockZ() { return z; } @@ -536,21 +530,6 @@ public BlockVector3 toBlockVector3(int y) { return BlockVector3.at(x, y, z); } - @Override - public boolean equals(Object obj) { - if (!(obj instanceof BlockVector2 other)) { - return false; - } - - return other.x == this.x && other.z == this.z; - - } - - @Override - public int hashCode() { - return (x << 16) ^ z; - } - @Override public String toString() { return "(" + x + ", " + z + ")"; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java index 132d8d5573..1e88233280 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java @@ -32,7 +32,7 @@ /** * An immutable 3-dimensional vector. */ -public final class BlockVector3 { +public record BlockVector3(int x, int y, int z) { public static final BlockVector3 ZERO = new BlockVector3(0, 0, 0); public static final BlockVector3 UNIT_X = new BlockVector3(1, 0, 0); @@ -112,23 +112,6 @@ public static Comparator sortByCoordsYzx() { return YzxOrderComparator.YZX_ORDER; } - private final int x; - private final int y; - private final int z; - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - private BlockVector3(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - public long toLongPackedForm() { checkLongPackable(this); return (x & BITS_26) | ((z & BITS_26) << 26) | (((y & BITS_12) << (26 + 26))); @@ -138,7 +121,9 @@ public long toLongPackedForm() { * Get the X coordinate. * * @return the x coordinate + * @deprecated use {@link #x()} instead */ + @Deprecated(forRemoval = true) public int getX() { return x; } @@ -147,7 +132,9 @@ public int getX() { * Get the X coordinate. * * @return the x coordinate + * @deprecated use {@link #x()} instead */ + @Deprecated(forRemoval = true) public int getBlockX() { return x; } @@ -166,7 +153,9 @@ public BlockVector3 withX(int x) { * Get the Y coordinate. * * @return the y coordinate + * @deprecated use {@link #y()} instead */ + @Deprecated(forRemoval = true) public int getY() { return y; } @@ -175,7 +164,9 @@ public int getY() { * Get the Y coordinate. * * @return the y coordinate + * @deprecated use {@link #y()} instead */ + @Deprecated(forRemoval = true) public int getBlockY() { return y; } @@ -194,7 +185,9 @@ public BlockVector3 withY(int y) { * Get the Z coordinate. * * @return the z coordinate + * @deprecated use {@link #z()} instead */ + @Deprecated(forRemoval = true) public int getZ() { return z; } @@ -203,7 +196,9 @@ public int getZ() { * Get the Z coordinate. * * @return the z coordinate + * @deprecated use {@link #z()} instead */ + @Deprecated(forRemoval = true) public int getBlockZ() { return z; } @@ -686,20 +681,6 @@ public Vector3 toVector3() { return Vector3.at(x, y, z); } - @Override - public boolean equals(Object obj) { - if (!(obj instanceof BlockVector3 other)) { - return false; - } - - return other.x == this.x && other.y == this.y && other.z == this.z; - } - - @Override - public int hashCode() { - return (x ^ (z << 12)) ^ (y << 24); - } - @Override public String toString() { return "(" + x + ", " + y + ", " + z + ")"; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java index 11d488842f..9838383694 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java @@ -24,7 +24,7 @@ /** * An immutable 2-dimensional vector. */ -public final class Vector2 { +public record Vector2(double x, double z) { public static final Vector2 ZERO = new Vector2(0, 0); public static final Vector2 UNIT_X = new Vector2(1, 0); @@ -50,27 +50,24 @@ public static Vector2 at(double x, double z) { return new Vector2(x, z); } - private final double x; - private final double z; - /** - * Construct an instance. + * Get the X coordinate. * - * @param x the X coordinate - * @param z the Z coordinate + * @return the x coordinate + * @deprecated use {@link #x()} instead */ - private Vector2(double x, double z) { - this.x = x; - this.z = z; + @Deprecated(forRemoval = true) + public double getX() { + return x; } /** - * Get the X coordinate. + * Get the X coordinate, aligned to the block grid. * - * @return the x coordinate + * @return the block-aligned x coordinate */ - public double getX() { - return x; + public int blockX() { + return (int) Math.floor(x); } /** @@ -83,11 +80,22 @@ public Vector2 withX(double x) { return Vector2.at(x, z); } + /** + * Get the Z coordinate, aligned to the block grid. + * + * @return the block-aligned z coordinate + */ + public int blockZ() { + return (int) Math.floor(z); + } + /** * Get the Z coordinate. * * @return the z coordinate + * @deprecated use {@link #z()} instead */ + @Deprecated(forRemoval = true) public double getZ() { return z; } @@ -457,24 +465,6 @@ public Vector3 toVector3(double y) { return Vector3.at(x, y, z); } - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector2 other)) { - return false; - } - - return other.x == this.x && other.z == this.z; - - } - - @Override - public int hashCode() { - int hash = 17; - hash = 31 * hash + Double.hashCode(x); - hash = 31 * hash + Double.hashCode(z); - return hash; - } - @Override public String toString() { return "(" + x + ", " + z + ")"; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java index 004175272d..e545d6238e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java @@ -29,7 +29,7 @@ /** * An immutable 3-dimensional vector. */ -public final class Vector3 { +public record Vector3(double x, double y, double z) { public static final Vector3 ZERO = new Vector3(0, 0, 0); public static final Vector3 UNIT_X = new Vector3(1, 0, 0); @@ -80,28 +80,22 @@ public static Comparator sortByCoordsYzx() { return YzxOrderComparator.YZX_ORDER; } - private final double x; - private final double y; - private final double z; - /** - * Construct an instance. + * Get the X coordinate, aligned to the block grid. * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate + * @return the block-aligned x coordinate */ - private Vector3(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; + public int blockX() { + return (int) Math.floor(x); } /** * Get the X coordinate. * * @return the x coordinate + * @deprecated use {@link #x()} instead */ + @Deprecated(forRemoval = true) public double getX() { return x; } @@ -116,11 +110,22 @@ public Vector3 withX(double x) { return Vector3.at(x, y, z); } + /** + * Get the Y coordinate, aligned to the block grid. + * + * @return the block-aligned y coordinate + */ + public int blockY() { + return (int) Math.floor(y); + } + /** * Get the Y coordinate. * * @return the y coordinate + * @deprecated use {@link #y()} instead */ + @Deprecated(forRemoval = true) public double getY() { return y; } @@ -135,11 +140,22 @@ public Vector3 withY(double y) { return Vector3.at(x, y, z); } + /** + * Get the Z coordinate, aligned to the block grid. + * + * @return the block-aligned z coordinate + */ + public int blockZ() { + return (int) Math.floor(z); + } + /** * Get the Z coordinate. * * @return the z coordinate + * @deprecated use {@link #z()} instead */ + @Deprecated(forRemoval = true) public double getZ() { return z; } @@ -588,24 +604,6 @@ public Vector2 toVector2() { return Vector2.at(x, z); } - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector3 other)) { - return false; - } - - return other.x == this.x && other.y == this.y && other.z == this.z; - } - - @Override - public int hashCode() { - int hash = 17; - hash = 31 * hash + Double.hashCode(x); - hash = 31 * hash + Double.hashCode(y); - hash = 31 * hash + Double.hashCode(z); - return hash; - } - @Override public String toString() { return "(" + x + ", " + y + ", " + z + ")";