Fix compatibility with WorldGuard (#2743)

* Make the Vector classes into Records (#2477)

* Make the Vector classes into Records

* Drop custom equals and hashCode methods in Vector/BlockVector classes

(cherry picked from commit 0df2b6af4c1ce18b77eedd5c62eeb45011512103)
Signed-off-by: Pierre Maurice Schwang <mail@pschwang.eu>

* chore: cleanup cherry-pick issues, migrate to new methods

* chore: add since attributes to deprecated tags, use MathMan instead of Math std lib for rounding ints

* chore: mark custom hashCode + equals implementations diffing from upstream

---------

Co-authored-by: Maddy Miller <mnmiller1@me.com>
This commit is contained in:
Pierre Maurice Schwang 2024-05-25 13:36:37 +02:00 committed by GitHub
parent f9c523c173
commit c77d34156b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 454 additions and 354 deletions

View File

@ -12,6 +12,6 @@ repositories {
dependencies { dependencies {
// url=https://repo.papermc.io/service/rest/repository/browse/maven-public/io/papermc/paper/dev-bundle/1.20.6-R0.1-SNAPSHOT/ // url=https://repo.papermc.io/service/rest/repository/browse/maven-public/io/papermc/paper/dev-bundle/1.20.6-R0.1-SNAPSHOT/
the<PaperweightUserDependenciesExtension>().paperDevBundle("1.20.6-R0.1-20240520.005421-60") the<PaperweightUserDependenciesExtension>().paperDevBundle("1.20.6-R0.1-20240523.202134-70")
compileOnly(libs.paperlib) compileOnly(libs.paperlib)
} }

View File

@ -31,18 +31,18 @@ public abstract class AbstractFilterBlock extends FilterBlock {
public abstract Extent getExtent(); public abstract Extent getExtent();
@Override @Override
public int getX() { public int x() {
return getPosition().getX(); return getPosition().x();
} }
@Override @Override
public int getY() { public int y() {
return getPosition().getY(); return getPosition().y();
} }
@Override @Override
public int getZ() { public int z() {
return getPosition().getZ(); return getPosition().z();
} }
@Override @Override
@ -72,12 +72,12 @@ public abstract class AbstractFilterBlock extends FilterBlock {
@Override @Override
public BlockVector3 getMinimumPoint() { public BlockVector3 getMinimumPoint() {
return at(getX(), getY(), getZ()); return at(x(), y(), z());
} }
@Override @Override
public BlockVector3 getMaximumPoint() { public BlockVector3 getMaximumPoint() {
return at(getX(), getY(), getZ()); return at(x(), y(), z());
} }
@Override @Override
@ -88,7 +88,7 @@ public abstract class AbstractFilterBlock extends FilterBlock {
@Override @Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block)
throws WorldEditException { throws WorldEditException {
if (x == this.getX() && y == this.getY() && z == this.getZ()) { if (x == this.x() && y == this.y() && z == this.z()) {
setFullBlock(block.toBaseBlock()); setFullBlock(block.toBaseBlock());
return true; return true;
} }
@ -97,7 +97,7 @@ public abstract class AbstractFilterBlock extends FilterBlock {
@Override @Override
public boolean setBiome(int x, int y, int z, BiomeType biome) { public boolean setBiome(int x, int y, int z, BiomeType biome) {
if (x == this.getX() && y == this.getY() && z == this.getZ()) { if (x == this.x() && y == this.y() && z == this.z()) {
setBiome(biome); setBiome(biome);
return true; return true;
} }

View File

@ -80,17 +80,17 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock {
} }
@Override @Override
public int getX() { public int x() {
return x; return x;
} }
@Override @Override
public int getY() { public int y() {
return (heights[index] & 0xFF) + yOffset; return (heights[index] & 0xFF) + yOffset;
} }
@Override @Override
public int getZ() { public int z() {
return z; return z;
} }
@ -112,12 +112,12 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock {
@Override @Override
public void setBiome(final BiomeType biome) { public void setBiome(final BiomeType biome) {
getExtent().setBiome(getX(), getY(), getZ(), biome); getExtent().setBiome(x(), y(), z(), biome);
} }
@Override @Override
public BiomeType getBiome() { public BiomeType getBiome() {
return getExtent().getBiomeType(getX(), getY(), getZ()); return getExtent().getBiomeType(x(), y(), z());
} }
} }

View File

@ -190,17 +190,17 @@ public class CharFilterBlock extends ChunkFilterBlock {
} }
@Override @Override
public final int getX() { public final int x() {
return xx + x; return xx + x;
} }
@Override @Override
public final int getY() { public final int y() {
return yy + y; return yy + y;
} }
@Override @Override
public final int getZ() { public final int z() {
return zz + z; return zz + z;
} }
@ -304,7 +304,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (z > 0) { if (z > 0) {
return states[getArr[index - 16]]; return states[getArr[index - 16]];
} }
return getExtent().getBlock(getX(), getY(), getZ() - 1); return getExtent().getBlock(x(), y(), z() - 1);
} }
@Override @Override
@ -312,7 +312,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (x < 15) { if (x < 15) {
return states[getArr[index + 1]]; return states[getArr[index + 1]];
} }
return getExtent().getBlock(getX() + 1, getY(), getZ()); return getExtent().getBlock(x() + 1, y(), z());
} }
@Override @Override
@ -320,7 +320,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (z < 15) { if (z < 15) {
return states[getArr[index + 16]]; return states[getArr[index + 16]];
} }
return getExtent().getBlock(getX(), getY(), getZ() + 1); return getExtent().getBlock(x(), y(), z() + 1);
} }
@Override @Override
@ -328,7 +328,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (x > 0) { if (x > 0) {
return states[getArr[index - 1]]; return states[getArr[index - 1]];
} }
return getExtent().getBlock(getX() - 1, getY(), getZ()); return getExtent().getBlock(x() - 1, y(), z());
} }
@Override @Override
@ -401,7 +401,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
@Override @Override
public boolean setBiome(BlockVector3 position, BiomeType biome) { public boolean setBiome(BlockVector3 position, BiomeType biome) {
return setBiome(position.getX(), position.getY(), position.getBlockZ(), biome); return setBiome(position.x(), position.y(), position.z(), biome);
} }
@Override @Override

View File

@ -73,60 +73,60 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
} }
public BlockState getBlockBelow() { public BlockState getBlockBelow() {
return getBlock(getX(), getY() - 1, getZ()); return getBlock(x(), y() - 1, z());
} }
public BlockState getBlockAbove() { public BlockState getBlockAbove() {
return getBlock(getX(), getY() + 1, getZ()); return getBlock(x(), y() + 1, z());
} }
public BlockState getBlockNorth() { public BlockState getBlockNorth() {
return getBlock(getX(), getY(), getZ() - 1); return getBlock(x(), y(), z() - 1);
} }
public BlockState getBlockEast() { public BlockState getBlockEast() {
return getBlock(getX() + 1, getY(), getZ()); return getBlock(x() + 1, y(), z());
} }
public BlockState getBlockSouth() { public BlockState getBlockSouth() {
return getBlock(getX(), getY(), getZ() + 1); return getBlock(x(), y(), z() + 1);
} }
public BlockState getBlockWest() { public BlockState getBlockWest() {
return getBlock(getX() - 1, getY(), getZ()); return getBlock(x() - 1, y(), z());
} }
public BlockState getBlockRelativeY(int y) { public BlockState getBlockRelativeY(int y) {
return getBlock(getX(), getY() + y, getZ()); return getBlock(x(), y() + y, z());
} }
@Override @Override
public abstract int getX(); public abstract int x();
@Override @Override
public abstract int getY(); public abstract int y();
@Override @Override
public abstract int getZ(); public abstract int z();
public int getLocalX() { public int getLocalX() {
return getX() & 15; return x() & 15;
} }
public int getLocalY() { public int getLocalY() {
return getY() & 15; return y() & 15;
} }
public int getLocalZ() { public int getLocalZ() {
return getZ() & 15; return z() & 15;
} }
public int getChunkX() { public int getChunkX() {
return getX() >> 4; return x() >> 4;
} }
public int getChunkZ() { public int getChunkZ() {
return getZ() >> 4; return z() >> 4;
} }
/* /*
@ -204,7 +204,7 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
@Override @Override
public boolean setBiome(BlockVector3 position, BiomeType biome) { public boolean setBiome(BlockVector3 position, BiomeType biome) {
return setBiome(position.getX(), position.getY(), position.getZ(), biome); return setBiome(position.x(), position.y(), position.z(), biome);
} }
} }

View File

@ -17,17 +17,17 @@ public class SingleFilterBlock extends AbstractSingleFilterBlock {
} }
@Override @Override
public int getX() { public int x() {
return x; return x;
} }
@Override @Override
public int getY() { public int y() {
return y; return y;
} }
@Override @Override
public int getZ() { public int z() {
return z; return z;
} }

View File

@ -95,13 +95,8 @@ public class DelegateBlockVector3 extends BlockVector3 {
} }
@Override @Override
public int getX() { public int x() {
return parent.getX(); return parent.x();
}
@Override
public int getBlockX() {
return parent.getBlockX();
} }
@Override @Override
@ -110,13 +105,8 @@ public class DelegateBlockVector3 extends BlockVector3 {
} }
@Override @Override
public int getY() { public int y() {
return parent.getY(); return parent.y();
}
@Override
public int getBlockY() {
return parent.getBlockY();
} }
@Override @Override
@ -125,13 +115,8 @@ public class DelegateBlockVector3 extends BlockVector3 {
} }
@Override @Override
public int getZ() { public int z() {
return parent.getZ(); return parent.z();
}
@Override
public int getBlockZ() {
return parent.getBlockZ();
} }
@Override @Override

View File

@ -21,11 +21,11 @@ public class MutableBlockVector3 extends BlockVector3 {
} }
public MutableBlockVector3(BlockVector3 other) { public MutableBlockVector3(BlockVector3 other) {
this(other.getX(), other.getY(), other.getZ()); this(other.x(), other.y(), other.z());
} }
public MutableBlockVector3 setComponents(BlockVector3 other) { public MutableBlockVector3 setComponents(BlockVector3 other) {
return setComponents(other.getBlockX(), other.getBlockY(), other.getBlockZ()); return setComponents(other.x(), other.y(), other.z());
} }
private int x; private int x;
@ -47,33 +47,33 @@ public class MutableBlockVector3 extends BlockVector3 {
} }
@Override @Override
public final int getX() { public final int x() {
return x; return x;
} }
@Override @Override
public final int getY() { public final int y() {
return y; return y;
} }
@Override @Override
public final int getZ() { public final int z() {
return z; return z;
} }
@Override @Override
public BlockVector3 getMinimum(BlockVector3 v2) { public BlockVector3 getMinimum(BlockVector3 v2) {
this.x = Math.min(v2.getX(), x); this.x = Math.min(v2.x(), x);
this.y = Math.min(v2.getY(), y); this.y = Math.min(v2.y(), y);
this.z = Math.min(v2.getZ(), z); this.z = Math.min(v2.z(), z);
return this; return this;
} }
@Override @Override
public BlockVector3 getMaximum(BlockVector3 v2) { public BlockVector3 getMaximum(BlockVector3 v2) {
this.x = Math.max(v2.getX(), x); this.x = Math.max(v2.x(), x);
this.y = Math.max(v2.getY(), y); this.y = Math.max(v2.y(), y);
this.z = Math.max(v2.getZ(), z); this.z = Math.max(v2.z(), z);
return this; return this;
} }

View File

@ -23,7 +23,7 @@ public class MutableVector3 extends Vector3 {
} }
public MutableVector3(Vector3 other) { public MutableVector3(Vector3 other) {
this(other.getX(), other.getY(), other.getZ()); this(other.x(), other.y(), other.z());
} }
public static MutableVector3 get(int x, int y, int z) { public static MutableVector3 get(int x, int y, int z) {
@ -36,9 +36,9 @@ public class MutableVector3 extends Vector3 {
@Override @Override
public MutableVector3 setComponents(Vector3 other) { public MutableVector3 setComponents(Vector3 other) {
this.x = other.getX(); this.x = other.x();
this.y = other.getY(); this.y = other.y();
this.z = other.getZ(); this.z = other.z();
return this; return this;
} }
@ -95,17 +95,17 @@ public class MutableVector3 extends Vector3 {
} }
@Override @Override
public double getX() { public double x() {
return x; return x;
} }
@Override @Override
public double getY() { public double y() {
return y; return y;
} }
@Override @Override
public double getZ() { public double z() {
return z; return z;
} }

View File

@ -11,18 +11,18 @@ public class OffsetBlockVector3 extends DelegateBlockVector3 {
} }
@Override @Override
public int getX() { public int x() {
return super.getX() + offset.getX(); return super.x() + offset.x();
} }
@Override @Override
public int getY() { public int y() {
return super.getY() + offset.getY(); return super.y() + offset.y();
} }
@Override @Override
public int getZ() { public int z() {
return super.getZ() + offset.getZ(); return super.z() + offset.z();
} }
} }

View File

@ -15,21 +15,21 @@ public class Vector3Impl extends Vector3 {
} }
public Vector3Impl(Vector3 other) { public Vector3Impl(Vector3 other) {
this(other.getX(), other.getY(), other.getZ()); this(other.x(), other.y(), other.z());
} }
@Override @Override
public final double getX() { public final double x() {
return x; return x;
} }
@Override @Override
public final double getY() { public final double y() {
return y; return y;
} }
@Override @Override
public final double getZ() { public final double z() {
return z; return z;
} }

View File

@ -27,7 +27,7 @@ import java.util.Comparator;
/** /**
* An immutable 2-dimensional vector. * An immutable 2-dimensional vector.
*/ */
//FAWE start - un-finalize //FAWE start - not a record
public class BlockVector2 { public class BlockVector2 {
//FAWE end //FAWE end
@ -122,7 +122,19 @@ public class BlockVector2 {
* Get the X coordinate. * Get the X coordinate.
* *
* @return the x coordinate * @return the x coordinate
* @since TODO
*/ */
public int x() {
return x;
}
/**
* Get the X coordinate.
*
* @return the x coordinate
* @deprecated use {@link #x()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public int getX() { public int getX() {
return x; return x;
} }
@ -131,7 +143,9 @@ public class BlockVector2 {
* Get the X coordinate. * Get the X coordinate.
* *
* @return the x coordinate * @return the x coordinate
* @deprecated use {@link #x()} instead
*/ */
@Deprecated(forRemoval = true, since = "TODO")
public int getBlockX() { public int getBlockX() {
return x; return x;
} }
@ -150,7 +164,19 @@ public class BlockVector2 {
* Get the Z coordinate. * Get the Z coordinate.
* *
* @return the z coordinate * @return the z coordinate
* @since TODO
*/ */
public int z() {
return z;
}
/**
* Get the Z coordinate.
*
* @return the z coordinate
* @deprecated use {@link #z()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public int getZ() { public int getZ() {
return z; return z;
} }
@ -159,7 +185,9 @@ public class BlockVector2 {
* Get the Z coordinate. * Get the Z coordinate.
* *
* @return the z coordinate * @return the z coordinate
* @deprecated use {@link #z()} instead
*/ */
@Deprecated(forRemoval = true, since = "TODO")
public int getBlockZ() { public int getBlockZ() {
return z; return z;
} }
@ -598,13 +626,13 @@ public class BlockVector2 {
return BlockVector3.at(x, y, z); return BlockVector3.at(x, y, z);
} }
//FAWE start - not a record, need own implementations
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof BlockVector2)) { if (!(obj instanceof BlockVector2 other)) {
return false; return false;
} }
BlockVector2 other = (BlockVector2) obj;
return other.x == this.x && other.z == this.z; return other.x == this.x && other.z == this.z;
} }
@ -613,6 +641,7 @@ public class BlockVector2 {
public int hashCode() { public int hashCode() {
return (x << 16) ^ z; return (x << 16) ^ z;
} }
//FAWE end
@Override @Override
public String toString() { public String toString() {

View File

@ -38,7 +38,9 @@ import static com.sk89q.worldedit.math.BitMath.unpackZ;
/** /**
* An immutable 3-dimensional vector. * An immutable 3-dimensional vector.
*/ */
//FAWE start - not a record
public abstract class BlockVector3 { public abstract class BlockVector3 {
//FAWE end
public static final BlockVector3 ZERO = BlockVector3.at(0, 0, 0); public static final BlockVector3 ZERO = BlockVector3.at(0, 0, 0);
public static final BlockVector3 UNIT_X = BlockVector3.at(1, 0, 0); public static final BlockVector3 UNIT_X = BlockVector3.at(1, 0, 0);
@ -85,9 +87,9 @@ public abstract class BlockVector3 {
} }
public static boolean isLongPackable(BlockVector3 location) { public static boolean isLongPackable(BlockVector3 location) {
return isHorizontallyInBounds(location.getX()) return isHorizontallyInBounds(location.x())
&& isHorizontallyInBounds(location.getZ()) && isHorizontallyInBounds(location.z())
&& WORLD_Y_MIN <= location.getY() && location.getY() <= WORLD_Y_MAX; && WORLD_Y_MIN <= location.y() && location.y() <= WORLD_Y_MAX;
} }
public static void checkLongPackable(BlockVector3 location) { public static void checkLongPackable(BlockVector3 location) {
@ -107,9 +109,9 @@ public abstract class BlockVector3 {
private static final class YzxOrderComparator { private static final class YzxOrderComparator {
private static final Comparator<BlockVector3> YZX_ORDER = private static final Comparator<BlockVector3> YZX_ORDER =
Comparator.comparingInt(BlockVector3::getY) Comparator.comparingInt(BlockVector3::y)
.thenComparingInt(BlockVector3::getZ) .thenComparingInt(BlockVector3::z)
.thenComparingInt(BlockVector3::getX); .thenComparingInt(BlockVector3::x);
} }
@ -135,57 +137,69 @@ public abstract class BlockVector3 {
public long toLongPackedForm() { public long toLongPackedForm() {
checkLongPackable(this); checkLongPackable(this);
return (getX() & BITS_26) | ((getZ() & BITS_26) << 26) | (((getY() & BITS_12) << (26 + 26))); return (x() & BITS_26) | ((z() & BITS_26) << 26) | (((y() & BITS_12) << (26 + 26)));
} }
public MutableBlockVector3 mutX(double x) { public MutableBlockVector3 mutX(double x) {
return new MutableBlockVector3((int) x, getY(), getZ()); return new MutableBlockVector3((int) x, y(), z());
} }
public MutableBlockVector3 mutY(double y) { public MutableBlockVector3 mutY(double y) {
return new MutableBlockVector3(getX(), (int) y, getZ()); return new MutableBlockVector3(x(), (int) y, z());
} }
public MutableBlockVector3 mutZ(double z) { public MutableBlockVector3 mutZ(double z) {
return new MutableBlockVector3(getX(), getY(), (int) z); return new MutableBlockVector3(x(), y(), (int) z);
} }
public MutableBlockVector3 mutX(int x) { public MutableBlockVector3 mutX(int x) {
return new MutableBlockVector3(x, getY(), getZ()); return new MutableBlockVector3(x, y(), z());
} }
public MutableBlockVector3 mutY(int y) { public MutableBlockVector3 mutY(int y) {
return new MutableBlockVector3(getX(), y, getZ()); return new MutableBlockVector3(x(), y, z());
} }
public MutableBlockVector3 mutZ(int z) { public MutableBlockVector3 mutZ(int z) {
return new MutableBlockVector3(getX(), getY(), z); return new MutableBlockVector3(x(), y(), z);
} }
public BlockVector3 toImmutable() { public BlockVector3 toImmutable() {
return BlockVector3.at(getX(), getY(), getZ()); return BlockVector3.at(x(), y(), z());
} }
//FAWE end //FAWE end
//FAWE start - make record getters to abstract methods
/** /**
* Get the X coordinate. * Get the X coordinate.
* *
* @return the x coordinate * @return the x coordinate
* @since TODO
*/ */
//FAWE start - Made abstract public abstract int x();
public abstract int getX();
//FAWE end //FAWE end
/** /**
* Get the X coordinate. * Get the X coordinate.
* *
* @return the x coordinate * @return the x coordinate
* @deprecated use {@link #x()} instead
*/ */
//FAWE start - getter @Deprecated(forRemoval = true, since = "TODO")
public int getX() {
return this.x(); //FAWE - access abstract getter instead of local field
}
/**
* Get the X coordinate.
*
* @return the x coordinate
* @deprecated use {@link #x()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public int getBlockX() { public int getBlockX() {
return getX(); return this.x(); //FAWE - access abstract getter instead of local field
} }
//FAWE end
/** /**
* Set the X coordinate. * Set the X coordinate.
@ -195,29 +209,42 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 withX(int x) { public BlockVector3 withX(int x) {
return BlockVector3.at(x, getY(), getZ()); return BlockVector3.at(x, y(), z());
} }
//FAWE end //FAWE end
//FAWE start - make record getters to abstract methods
/** /**
* Get the Y coordinate. * Get the Y coordinate.
* *
* @return the y coordinate * @return the y coordinate
* @since TODO
*/ */
//FAWE start - Made abstract public abstract int y();
public abstract int getY();
//FAWE end //FAWE end
/** /**
* Get the Y coordinate. * Get the Y coordinate.
* *
* @return the y coordinate * @return the y coordinate
* @deprecated use {@link #y()} instead
*/ */
//FAWE start - getter @Deprecated(forRemoval = true, since = "TODO")
public int getY() {
return this.y(); //FAWE - access abstract getter instead of local field
}
/**
* Get the Y coordinate.
*
* @return the y coordinate
* @deprecated use {@link #y()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public int getBlockY() { public int getBlockY() {
return getY(); return this.y(); //FAWE - access abstract getter instead of local field
} }
//FAWE end
/** /**
* Set the Y coordinate. * Set the Y coordinate.
@ -231,25 +258,37 @@ public abstract class BlockVector3 {
} }
//FAWE end //FAWE end
//FAWE start - make record getters to abstract methods
/** /**
* Get the Z coordinate. * Get the Z coordinate.
* *
* @return the z coordinate * @return the Z coordinate
* @since TODO
*/ */
//FAWE start - Made abstract public abstract int z();
public abstract int getZ();
//FAWE end //FAWE end
/** /**
* Get the Z coordinate. * Get the Z coordinate.
* *
* @return the z coordinate * @return the z coordinate
* @deprecated use {@link #z()} instead
*/ */
//FAWE start - getter @Deprecated(forRemoval = true, since = "TODO")
public int getBlockZ() { public int getZ() {
return getZ(); return this.z(); //FAWE - access abstract getter instead of local field
}
/**
* Get the Z coordinate.
*
* @return the z coordinate
* @deprecated use {@link #z()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public int getBlockZ() {
return this.z(); //FAWE - access abstract getter instead of local field
} }
//FAWE end
/** /**
* Set the Z coordinate. * Set the Z coordinate.
@ -259,7 +298,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 withZ(int z) { public BlockVector3 withZ(int z) {
return BlockVector3.at(getX(), getY(), z); return BlockVector3.at(x(), y(), z);
} }
//FAWE end //FAWE end
@ -271,7 +310,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 add(BlockVector3 other) { public BlockVector3 add(BlockVector3 other) {
return add(other.getX(), other.getY(), other.getZ()); return add(other.x(), other.y(), other.z());
} }
//FAWE end //FAWE end
@ -285,7 +324,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 add(int x, int y, int z) { public BlockVector3 add(int x, int y, int z) {
return BlockVector3.at(this.getX() + x, this.getY() + y, this.getZ() + z); return BlockVector3.at(this.x() + x, this.y() + y, this.z() + z);
} }
//FAWE end //FAWE end
@ -298,14 +337,14 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 add(BlockVector3... others) { public BlockVector3 add(BlockVector3... others) {
int newX = getX(); int newX = x();
int newY = getY(); int newY = y();
int newZ = getZ(); int newZ = z();
for (BlockVector3 other : others) { for (BlockVector3 other : others) {
newX += other.getX(); newX += other.x();
newY += other.getY(); newY += other.y();
newZ += other.getZ(); newZ += other.z();
} }
return BlockVector3.at(newX, newY, newZ); return BlockVector3.at(newX, newY, newZ);
@ -321,7 +360,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 subtract(BlockVector3 other) { public BlockVector3 subtract(BlockVector3 other) {
return subtract(other.getX(), other.getY(), other.getZ()); return subtract(other.x(), other.y(), other.z());
} }
//FAWE end //FAWE end
@ -336,7 +375,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 subtract(int x, int y, int z) { public BlockVector3 subtract(int x, int y, int z) {
return BlockVector3.at(this.getX() - x, this.getY() - y, this.getZ() - z); return BlockVector3.at(this.x() - x, this.y() - y, this.z() - z);
} }
//FAWE end //FAWE end
@ -349,14 +388,14 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 subtract(BlockVector3... others) { public BlockVector3 subtract(BlockVector3... others) {
int newX = getX(); int newX = x();
int newY = getY(); int newY = y();
int newZ = getZ(); int newZ = z();
for (BlockVector3 other : others) { for (BlockVector3 other : others) {
newX -= other.getX(); newX -= other.x();
newY -= other.getY(); newY -= other.y();
newZ -= other.getZ(); newZ -= other.z();
} }
return BlockVector3.at(newX, newY, newZ); return BlockVector3.at(newX, newY, newZ);
@ -371,7 +410,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 multiply(BlockVector3 other) { public BlockVector3 multiply(BlockVector3 other) {
return multiply(other.getX(), other.getY(), other.getZ()); return multiply(other.x(), other.y(), other.z());
} }
//FAWE end //FAWE end
@ -385,7 +424,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 multiply(int x, int y, int z) { public BlockVector3 multiply(int x, int y, int z) {
return BlockVector3.at(this.getX() * x, this.getY() * y, this.getZ() * z); return BlockVector3.at(this.x() * x, this.y() * y, this.z() * z);
} }
//FAWE end //FAWE end
@ -397,14 +436,14 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 multiply(BlockVector3... others) { public BlockVector3 multiply(BlockVector3... others) {
int newX = getX(); int newX = x();
int newY = getY(); int newY = y();
int newZ = getZ(); int newZ = z();
for (BlockVector3 other : others) { for (BlockVector3 other : others) {
newX *= other.getX(); newX *= other.x();
newY *= other.getY(); newY *= other.y();
newZ *= other.getZ(); newZ *= other.z();
} }
return BlockVector3.at(newX, newY, newZ); return BlockVector3.at(newX, newY, newZ);
@ -429,7 +468,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 divide(BlockVector3 other) { public BlockVector3 divide(BlockVector3 other) {
return divide(other.getX(), other.getY(), other.getZ()); return divide(other.x(), other.y(), other.z());
} }
//FAWE end //FAWE end
@ -443,7 +482,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 divide(int x, int y, int z) { public BlockVector3 divide(int x, int y, int z) {
return BlockVector3.at(this.getX() / x, this.getY() / y, this.getZ() / z); return BlockVector3.at(this.x() / x, this.y() / y, this.z() / z);
} }
//FAWE end //FAWE end
@ -467,7 +506,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 shr(int x, int y, int z) { public BlockVector3 shr(int x, int y, int z) {
return at(this.getX() >> x, this.getY() >> y, this.getZ() >> z); return at(this.x() >> x, this.y() >> y, this.z() >> z);
} }
//FAWE end //FAWE end
@ -491,7 +530,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 shl(int x, int y, int z) { public BlockVector3 shl(int x, int y, int z) {
return at(this.getX() << x, this.getY() << y, this.getZ() << z); return at(this.x() << x, this.y() << y, this.z() << z);
} }
//FAWE end //FAWE end
@ -521,7 +560,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public int lengthSq() { public int lengthSq() {
return getX() * getX() + getY() * getY() + getZ() * getZ(); return x() * x() + y() * y() + z() * z();
} }
//FAWE end //FAWE end
@ -543,9 +582,9 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public int distanceSq(BlockVector3 other) { public int distanceSq(BlockVector3 other) {
int dx = other.getX() - getX(); int dx = other.x() - x();
int dy = other.getY() - getY(); int dy = other.y() - y();
int dz = other.getZ() - getZ(); int dz = other.z() - z();
return dx * dx + dy * dy + dz * dz; return dx * dx + dy * dy + dz * dz;
} }
//FAWE end //FAWE end
@ -559,9 +598,9 @@ public abstract class BlockVector3 {
//FAWE start - getter //FAWE start - getter
public BlockVector3 normalize() { public BlockVector3 normalize() {
double len = length(); double len = length();
double x = this.getX() / len; double x = this.x() / len;
double y = this.getY() / len; double y = this.y() / len;
double z = this.getZ() / len; double z = this.z() / len;
return BlockVector3.at(x, y, z); return BlockVector3.at(x, y, z);
} }
//FAWE end //FAWE end
@ -574,7 +613,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public double dot(BlockVector3 other) { public double dot(BlockVector3 other) {
return getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ(); return x() * other.x() + y() * other.y() + z() * other.z();
} }
//FAWE end //FAWE end
@ -587,9 +626,9 @@ public abstract class BlockVector3 {
//FAWE start - getter //FAWE start - getter
public BlockVector3 cross(BlockVector3 other) { public BlockVector3 cross(BlockVector3 other) {
return new BlockVector3Imp( return new BlockVector3Imp(
getY() * other.getZ() - getZ() * other.getY(), y() * other.z() - z() * other.y(),
getZ() * other.getX() - getX() * other.getZ(), z() * other.x() - x() * other.z(),
getX() * other.getY() - getY() * other.getX() x() * other.y() - y() * other.x()
); );
} }
//FAWE end //FAWE end
@ -603,8 +642,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public boolean containedWithin(BlockVector3 min, BlockVector3 max) { public boolean containedWithin(BlockVector3 min, BlockVector3 max) {
return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max return x() >= min.x() && x() <= max.x() && y() >= min.y() && y() <= max.y() && z() >= min.z() && z() <= max.z();
.getY() && getZ() >= min.getZ() && getZ() <= max.getZ();
} }
//FAWE end //FAWE end
@ -618,11 +656,11 @@ public abstract class BlockVector3 {
//FAWE start - getter //FAWE start - getter
public BlockVector3 clampY(int min, int max) { public BlockVector3 clampY(int min, int max) {
checkArgument(min <= max, "minimum cannot be greater than maximum"); checkArgument(min <= max, "minimum cannot be greater than maximum");
if (getY() < min) { if (y() < min) {
return BlockVector3.at(getX(), min, getZ()); return BlockVector3.at(x(), min, z());
} }
if (getY() > max) { if (y() > max) {
return BlockVector3.at(getX(), max, getZ()); return BlockVector3.at(x(), max, z());
} }
return this; return this;
} }
@ -668,7 +706,7 @@ public abstract class BlockVector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 abs() { public BlockVector3 abs() {
return BlockVector3.at(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); return BlockVector3.at(Math.abs(x()), Math.abs(y()), Math.abs(z()));
} }
//FAWE end //FAWE end
@ -686,8 +724,8 @@ public abstract class BlockVector3 {
//FAWE start - getter //FAWE start - getter
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle); angle = Math.toRadians(angle);
double x = this.getX() - aboutX; double x = this.x() - aboutX;
double z = this.getZ() - aboutZ; double z = this.z() - aboutZ;
double cos = Math.cos(angle); double cos = Math.cos(angle);
double sin = Math.sin(angle); double sin = Math.sin(angle);
double x2 = x * cos - z * sin; double x2 = x * cos - z * sin;
@ -695,7 +733,7 @@ public abstract class BlockVector3 {
return BlockVector3.at( return BlockVector3.at(
x2 + aboutX + translateX, x2 + aboutX + translateX,
getY(), y(),
z2 + aboutZ + translateZ z2 + aboutZ + translateZ
); );
} }
@ -707,16 +745,16 @@ public abstract class BlockVector3 {
* @return pitch in radians * @return pitch in radians
*/ */
public double toPitch() { public double toPitch() {
double x = getX(); double x = x();
double z = getZ(); double z = z();
if (x == 0 && z == 0) { if (x == 0 && z == 0) {
return getY() > 0 ? -90 : 90; return y() > 0 ? -90 : 90;
} else { } else {
double x2 = x * x; double x2 = x * x;
double z2 = z * z; double z2 = z * z;
double xz = Math.sqrt(x2 + z2); double xz = Math.sqrt(x2 + z2);
return Math.toDegrees(Math.atan(-getY() / xz)); return Math.toDegrees(Math.atan(-y() / xz));
} }
} }
@ -726,8 +764,8 @@ public abstract class BlockVector3 {
* @return yaw in radians * @return yaw in radians
*/ */
public double toYaw() { public double toYaw() {
double x = getX(); double x = x();
double z = getZ(); double z = z();
double t = Math.atan2(-x, z); double t = Math.atan2(-x, z);
double tau = 2 * Math.PI; double tau = 2 * Math.PI;
@ -744,9 +782,9 @@ public abstract class BlockVector3 {
//FAWE start - getter //FAWE start - getter
public BlockVector3 getMinimum(BlockVector3 v2) { public BlockVector3 getMinimum(BlockVector3 v2) {
return new BlockVector3Imp( return new BlockVector3Imp(
Math.min(getX(), v2.getX()), Math.min(x(), v2.x()),
Math.min(getY(), v2.getY()), Math.min(y(), v2.y()),
Math.min(getZ(), v2.getZ()) Math.min(z(), v2.z())
); );
} }
//FAWE end //FAWE end
@ -760,9 +798,9 @@ public abstract class BlockVector3 {
//FAWE start - getter //FAWE start - getter
public BlockVector3 getMaximum(BlockVector3 v2) { public BlockVector3 getMaximum(BlockVector3 v2) {
return new BlockVector3Imp( return new BlockVector3Imp(
Math.max(getX(), v2.getX()), Math.max(x(), v2.x()),
Math.max(getY(), v2.getY()), Math.max(y(), v2.y()),
Math.max(getZ(), v2.getZ()) Math.max(z(), v2.z())
); );
} }
//FAWE end //FAWE end
@ -815,19 +853,19 @@ public abstract class BlockVector3 {
} }
public CompoundTag getNbtData(Extent orDefault) { public CompoundTag getNbtData(Extent orDefault) {
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData(); return orDefault.getFullBlock(x(), y(), z()).getNbtData();
} }
public BlockState getOrdinalBelow(Extent orDefault) { public BlockState getOrdinalBelow(Extent orDefault) {
return orDefault.getBlock(getX(), getY() - 1, getZ()); return orDefault.getBlock(x(), y() - 1, z());
} }
public BlockState getStateAbove(Extent orDefault) { public BlockState getStateAbove(Extent orDefault) {
return orDefault.getBlock(getX(), getY() + 1, getZ()); return orDefault.getBlock(x(), y() + 1, z());
} }
public BlockState getStateRelativeY(Extent orDefault, final int y) { public BlockState getStateRelativeY(Extent orDefault, final int y) {
return orDefault.getBlock(getX(), getY() + y, getZ()); return orDefault.getBlock(x(), y() + y, z());
} }
/** /**
@ -836,21 +874,21 @@ public abstract class BlockVector3 {
* @return a new {@link BlockVector2} * @return a new {@link BlockVector2}
*/ */
public BlockVector2 toBlockVector2() { public BlockVector2 toBlockVector2() {
return BlockVector2.at(getX(), getZ()); return BlockVector2.at(x(), z());
} }
public Vector3 toVector3() { public Vector3 toVector3() {
return Vector3.at(getX(), getY(), getZ()); return Vector3.at(x(), y(), z());
} }
//FAWE start - not a record, need own implementations
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof BlockVector3)) { if (!(obj instanceof final BlockVector3 other)) {
return false; return false;
} }
BlockVector3 other = (BlockVector3) obj; return other.x() == this.x() && other.y() == this.y() && other.z() == this.z();
return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ();
} }
public final boolean equals(BlockVector3 other) { public final boolean equals(BlockVector3 other) {
@ -858,17 +896,18 @@ public abstract class BlockVector3 {
return false; return false;
} }
return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ(); return other.x() == this.x() && other.y() == this.y() && other.z() == this.z();
} }
@Override @Override
public int hashCode() { public int hashCode() {
return (getX() ^ (getZ() << 12)) ^ (getY() << 24); return (x() ^ (z() << 12)) ^ (y() << 24);
} }
//FAWE end
@Override @Override
public String toString() { public String toString() {
return "(" + getX() + ", " + getY() + ", " + getZ() + ")"; return "(" + x() + ", " + y() + ", " + z() + ")";
} }
/** /**
@ -877,7 +916,7 @@ public abstract class BlockVector3 {
* @return string * @return string
*/ */
public String toParserString() { public String toParserString() {
return getX() + "," + getY() + "," + getZ(); return x() + "," + y() + "," + z();
} }
//Used by VS fork //Used by VS fork

View File

@ -56,33 +56,33 @@ public final class BlockVector3Imp extends BlockVector3 {
} }
@Override @Override
public final int getX() { public int x() {
return x; return x;
} }
@Override @Override
public final int getY() { public int y() {
return y; return y;
} }
@Override @Override
public final int getZ() { public int z() {
return z; return z;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return (getX() ^ (getZ() << 12)) ^ (getY() << 24); return (x() ^ (z() << 12)) ^ (y() << 24);
} }
@Override @Override
public final BlockVector3 toImmutable() { public BlockVector3 toImmutable() {
return this; return this;
} }
@Override @Override
public String toString() { public String toString() {
return "(" + getX() + ", " + getY() + ", " + getZ() + ")"; return "(" + x() + ", " + y() + ", " + z() + ")";
} }
} }

View File

@ -19,12 +19,13 @@
package com.sk89q.worldedit.math; package com.sk89q.worldedit.math;
import com.fastasyncworldedit.core.util.MathMan;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
/** /**
* An immutable 2-dimensional vector. * 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 ZERO = new Vector2(0, 0);
public static final Vector2 UNIT_X = new Vector2(1, 0); public static final Vector2 UNIT_X = new Vector2(1, 0);
@ -50,29 +51,27 @@ public final class Vector2 {
return new Vector2(x, z); return new Vector2(x, z);
} }
private final double x;
private final double z;
/**
* Construct an instance.
*
* @param x the X coordinate
* @param z the Z coordinate
*/
private Vector2(double x, double z) {
this.x = x;
this.z = z;
}
/** /**
* Get the X coordinate. * Get the X coordinate.
* *
* @return the x coordinate * @return the x coordinate
* @deprecated use {@link #x()} instead
*/ */
@Deprecated(forRemoval = true, since = "TODO")
public double getX() { public double getX() {
return x; return x;
} }
/**
* Get the X coordinate, aligned to the block grid.
*
* @return the block-aligned x coordinate
* @since TODO
*/
public int blockX() {
return MathMan.roundInt(x);
}
/** /**
* Set the X coordinate. * Set the X coordinate.
* *
@ -83,11 +82,23 @@ public final class Vector2 {
return Vector2.at(x, z); return Vector2.at(x, z);
} }
/**
* Get the Z coordinate, aligned to the block grid.
*
* @return the block-aligned z coordinate
* @since TODO
*/
public int blockZ() {
return MathMan.roundInt(z);
}
/** /**
* Get the Z coordinate. * Get the Z coordinate.
* *
* @return the z coordinate * @return the z coordinate
* @deprecated use {@link #z()} instead
*/ */
@Deprecated(forRemoval = true, since = "TODO")
public double getZ() { public double getZ() {
return z; return z;
} }
@ -458,24 +469,6 @@ public final class Vector2 {
return Vector3.at(x, y, z); return Vector3.at(x, y, z);
} }
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Vector2)) {
return false;
}
Vector2 other = (Vector2) obj;
return other.x == this.x && other.z == this.z;
}
@Override
public int hashCode() {
//FAWE start - XOR over x z calc
return (int) x << 16 ^ (int) z;
//FAWE end
}
@Override @Override
public String toString() { public String toString() {
return "(" + x + ", " + z + ")"; return "(" + x + ", " + z + ")";

View File

@ -32,7 +32,9 @@ import static com.google.common.base.Preconditions.checkArgument;
/** /**
* An immutable 3-dimensional vector. * An immutable 3-dimensional vector.
*/ */
//FAWE start - not a record, make abstract
public abstract class Vector3 { public abstract class Vector3 {
//FAWE end
public static final Vector3 ZERO = Vector3.at(0, 0, 0); public static final Vector3 ZERO = Vector3.at(0, 0, 0);
public static final Vector3 UNIT_X = Vector3.at(1, 0, 0); public static final Vector3 UNIT_X = Vector3.at(1, 0, 0);
@ -69,9 +71,9 @@ public abstract class Vector3 {
private static final Comparator<Vector3> YZX_ORDER = (a, b) -> { private static final Comparator<Vector3> YZX_ORDER = (a, b) -> {
return ComparisonChain.start() return ComparisonChain.start()
.compare(a.getY(), b.getY()) .compare(a.y(), b.y())
.compare(a.getZ(), b.getZ()) .compare(a.z(), b.z())
.compare(a.getX(), b.getX()) .compare(a.x(), b.x())
.result(); .result();
}; };
@ -96,7 +98,7 @@ public abstract class Vector3 {
* @return the x coordinate * @return the x coordinate
*/ */
public int getBlockX() { public int getBlockX() {
return MathMan.roundInt(getX()); return MathMan.roundInt(x());
} }
/** /**
@ -105,7 +107,7 @@ public abstract class Vector3 {
* @return the y coordinate * @return the y coordinate
*/ */
public int getBlockY() { public int getBlockY() {
return MathMan.roundInt(getY()); return MathMan.roundInt(y());
} }
/** /**
@ -114,7 +116,7 @@ public abstract class Vector3 {
* @return the z coordinate * @return the z coordinate
*/ */
public int getBlockZ() { public int getBlockZ() {
return MathMan.roundInt(getZ()); return MathMan.roundInt(z());
} }
public MutableVector3 setComponents(Vector3 other) { public MutableVector3 setComponents(Vector3 other) {
@ -130,27 +132,27 @@ public abstract class Vector3 {
} }
public MutableVector3 mutX(int x) { public MutableVector3 mutX(int x) {
return new MutableVector3(x, getY(), getZ()); return new MutableVector3(x, y(), z());
} }
public MutableVector3 mutX(double x) { public MutableVector3 mutX(double x) {
return new MutableVector3(x, getY(), getZ()); return new MutableVector3(x, y(), z());
} }
public MutableVector3 mutY(int y) { public MutableVector3 mutY(int y) {
return new MutableVector3(getX(), y, getZ()); return new MutableVector3(x(), y, z());
} }
public MutableVector3 mutY(double y) { public MutableVector3 mutY(double y) {
return new MutableVector3(getX(), y, getZ()); return new MutableVector3(x(), y, z());
} }
public MutableVector3 mutZ(int z) { public MutableVector3 mutZ(int z) {
return new MutableVector3(getX(), getY(), z); return new MutableVector3(x(), y(), z);
} }
public MutableVector3 mutZ(double z) { public MutableVector3 mutZ(double z) {
return new MutableVector3(getX(), getY(), z); return new MutableVector3(x(), y(), z);
} }
//FAWE end //FAWE end
@ -158,10 +160,29 @@ public abstract class Vector3 {
* Get the X coordinate. * Get the X coordinate.
* *
* @return the x coordinate * @return the x coordinate
* @since TODO
*/ */
//FAWE start - made abstract public abstract double x();
public abstract double getX();
//FAWE end /**
* Get the X coordinate, aligned to the block grid.
*
* @return the block-aligned x coordinate
*/
public int blockX() {
return MathMan.roundInt(this.x());
}
/**
* Get the X coordinate.
*
* @return the x coordinate
* @deprecated use {@link #x()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public double getX() {
return this.x();
}
/** /**
* Set the X coordinate. * Set the X coordinate.
@ -171,18 +192,38 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 withX(double x) { public Vector3 withX(double x) {
return Vector3.at(x, getY(), getZ()); return Vector3.at(x, y(), z());
} }
//FAWE end //FAWE end
/** /**
* Get the Y coordinate. * Get the Y coordinate.
* *
* @return the y coordinate * @return the y coordinate
* @since TODO
*/ */
//FAWE start - made abstract public abstract double y();
public abstract double getY();
//FAWE end /**
* Get the Y coordinate, aligned to the block grid.
*
* @return the block-aligned y coordinate
*/
public int blockY() {
return MathMan.roundInt(this.y());
}
/**
* Get the Y coordinate.
*
* @return the y coordinate
* @deprecated use {@link #y()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public double getY() {
return this.y();
}
/** /**
* Set the Y coordinate. * Set the Y coordinate.
@ -192,7 +233,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 withY(double y) { public Vector3 withY(double y) {
return Vector3.at(getX(), y, getZ()); return Vector3.at(x(), y, z());
} }
//FAWE end //FAWE end
@ -200,10 +241,29 @@ public abstract class Vector3 {
* Get the Z coordinate. * Get the Z coordinate.
* *
* @return the z coordinate * @return the z coordinate
* @since TODO
*/ */
//FAWE start - made abstract public abstract double z();
public abstract double getZ();
//FAWE end /**
* Get the Z coordinate, aligned to the block grid.
*
* @return the block-aligned z coordinate
*/
public int blockZ() {
return MathMan.roundInt(this.z());
}
/**
* Get the Z coordinate.
*
* @return the z coordinate
* @deprecated use {@link #z()} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
public double getZ() {
return this.z();
}
/** /**
* Set the Z coordinate. * Set the Z coordinate.
@ -213,7 +273,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 withZ(double z) { public Vector3 withZ(double z) {
return Vector3.at(getX(), getY(), z); return Vector3.at(x(), y(), z);
} }
//FAWE end //FAWE end
@ -225,7 +285,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 add(Vector3 other) { public Vector3 add(Vector3 other) {
return add(other.getX(), other.getY(), other.getZ()); return add(other.x(), other.y(), other.z());
} }
//FAWE end //FAWE end
@ -239,7 +299,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 add(double x, double y, double z) { public Vector3 add(double x, double y, double z) {
return Vector3.at(this.getX() + x, this.getY() + y, this.getZ() + z); return Vector3.at(this.x() + x, this.y() + y, this.z() + z);
} }
//FAWE end //FAWE end
@ -252,14 +312,14 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 add(Vector3... others) { public Vector3 add(Vector3... others) {
double newX = getX(); double newX = x();
double newY = getY(); double newY = y();
double newZ = getZ(); double newZ = z();
for (Vector3 other : others) { for (Vector3 other : others) {
newX += other.getX(); newX += other.x();
newY += other.getY(); newY += other.y();
newZ += other.getZ(); newZ += other.z();
} }
return Vector3.at(newX, newY, newZ); return Vector3.at(newX, newY, newZ);
@ -275,7 +335,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 subtract(Vector3 other) { public Vector3 subtract(Vector3 other) {
return subtract(other.getX(), other.getY(), other.getZ()); return subtract(other.x(), other.y(), other.z());
} }
//FAWE end //FAWE end
@ -290,7 +350,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 subtract(double x, double y, double z) { public Vector3 subtract(double x, double y, double z) {
return Vector3.at(this.getX() - x, this.getY() - y, this.getZ() - z); return Vector3.at(this.x() - x, this.y() - y, this.z() - z);
} }
//FAWE end //FAWE end
@ -303,14 +363,14 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 subtract(Vector3... others) { public Vector3 subtract(Vector3... others) {
double newX = getX(); double newX = x();
double newY = getY(); double newY = y();
double newZ = getZ(); double newZ = z();
for (Vector3 other : others) { for (Vector3 other : others) {
newX -= other.getX(); newX -= other.x();
newY -= other.getY(); newY -= other.y();
newZ -= other.getZ(); newZ -= other.z();
} }
return Vector3.at(newX, newY, newZ); return Vector3.at(newX, newY, newZ);
@ -325,7 +385,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 multiply(Vector3 other) { public Vector3 multiply(Vector3 other) {
return multiply(other.getX(), other.getY(), other.getZ()); return multiply(other.x(), other.y(), other.z());
} }
//FAWE end //FAWE end
@ -339,7 +399,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 multiply(double x, double y, double z) { public Vector3 multiply(double x, double y, double z) {
return Vector3.at(this.getX() * x, this.getY() * y, this.getZ() * z); return Vector3.at(this.x() * x, this.y() * y, this.z() * z);
} }
//FAWE end //FAWE end
@ -351,14 +411,14 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 multiply(Vector3... others) { public Vector3 multiply(Vector3... others) {
double newX = getX(); double newX = x();
double newY = getY(); double newY = y();
double newZ = getZ(); double newZ = z();
for (Vector3 other : others) { for (Vector3 other : others) {
newX *= other.getX(); newX *= other.x();
newY *= other.getY(); newY *= other.y();
newZ *= other.getZ(); newZ *= other.z();
} }
return Vector3.at(newX, newY, newZ); return Vector3.at(newX, newY, newZ);
@ -383,7 +443,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 divide(Vector3 other) { public Vector3 divide(Vector3 other) {
return divide(other.getX(), other.getY(), other.getZ()); return divide(other.x(), other.y(), other.z());
} }
//FAWE end //FAWE end
@ -397,7 +457,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 divide(double x, double y, double z) { public Vector3 divide(double x, double y, double z) {
return Vector3.at(this.getX() / x, this.getY() / y, this.getZ() / z); return Vector3.at(this.x() / x, this.y() / y, this.z() / z);
} }
//FAWE end //FAWE end
@ -427,7 +487,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public double lengthSq() { public double lengthSq() {
return getX() * getX() + getY() * getY() + getZ() * getZ(); return x() * x() + y() * y() + z() * z();
} }
//FAWE end //FAWE end
@ -449,9 +509,9 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public double distanceSq(Vector3 other) { public double distanceSq(Vector3 other) {
double dx = other.getX() - getX(); double dx = other.x() - x();
double dy = other.getY() - getY(); double dy = other.y() - y();
double dz = other.getZ() - getZ(); double dz = other.z() - z();
return dx * dx + dy * dy + dz * dz; return dx * dx + dy * dy + dz * dz;
} }
//FAWE end //FAWE end
@ -474,7 +534,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public double dot(Vector3 other) { public double dot(Vector3 other) {
return getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ(); return x() * other.x() + y() * other.y() + z() * other.z();
} }
//FAWE end //FAWE end
@ -487,9 +547,9 @@ public abstract class Vector3 {
//FAWE start - getter //FAWE start - getter
public Vector3 cross(Vector3 other) { public Vector3 cross(Vector3 other) {
return Vector3.at( return Vector3.at(
getY() * other.getZ() - getZ() * other.getY(), y() * other.z() - z() * other.y(),
getZ() * other.getX() - getX() * other.getZ(), z() * other.x() - x() * other.z(),
getX() * other.getY() - getY() * other.getX() x() * other.y() - y() * other.x()
); );
} }
//FAWE end //FAWE end
@ -503,8 +563,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public boolean containedWithin(Vector3 min, Vector3 max) { public boolean containedWithin(Vector3 min, Vector3 max) {
return getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max.getY() && getZ() >= min.getZ() && getZ() <= max return x() >= min.x() && x() <= max.x() && y() >= min.y() && y() <= max.y() && z() >= min.z() && z() <= max.z();
.getZ();
} }
//FAWE end //FAWE end
@ -518,11 +577,11 @@ public abstract class Vector3 {
//FAWE start - getter //FAWE start - getter
public Vector3 clampY(int min, int max) { public Vector3 clampY(int min, int max) {
checkArgument(min <= max, "minimum cannot be greater than maximum"); checkArgument(min <= max, "minimum cannot be greater than maximum");
if (getY() < min) { if (y() < min) {
return Vector3.at(getX(), min, getZ()); return Vector3.at(x(), min, z());
} }
if (getY() > max) { if (y() > max) {
return Vector3.at(getX(), max, getZ()); return Vector3.at(x(), max, z());
} }
return this; return this;
} }
@ -535,7 +594,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 floor() { public Vector3 floor() {
return Vector3.at(Math.floor(getX()), Math.floor(getY()), Math.floor(getZ())); return Vector3.at(Math.floor(x()), Math.floor(y()), Math.floor(z()));
} }
//FAWE end //FAWE end
@ -546,7 +605,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 ceil() { public Vector3 ceil() {
return Vector3.at(Math.ceil(getX()), Math.ceil(getY()), Math.ceil(getZ())); return Vector3.at(Math.ceil(x()), Math.ceil(y()), Math.ceil(z()));
} }
//FAWE end //FAWE end
@ -559,7 +618,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 round() { public Vector3 round() {
return Vector3.at(Math.floor(getX() + 0.5), Math.floor(getY() + 0.5), Math.floor(getZ() + 0.5)); return Vector3.at(Math.floor(x() + 0.5), Math.floor(y() + 0.5), Math.floor(z() + 0.5));
} }
//FAWE end //FAWE end
@ -570,7 +629,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 roundHalfUp() { public Vector3 roundHalfUp() {
return Vector3.at(MathUtils.roundHalfUp(getX()), MathUtils.roundHalfUp(getY()), MathUtils.roundHalfUp(getZ())); return Vector3.at(MathUtils.roundHalfUp(x()), MathUtils.roundHalfUp(y()), MathUtils.roundHalfUp(z()));
} }
//FAWE end //FAWE end
@ -582,7 +641,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector3 abs() { public Vector3 abs() {
return Vector3.at(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ())); return Vector3.at(Math.abs(x()), Math.abs(y()), Math.abs(z()));
} }
//FAWE end //FAWE end
@ -600,8 +659,8 @@ public abstract class Vector3 {
//FAWE start - getter //FAWE start - getter
public Vector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { public Vector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
angle = Math.toRadians(angle); angle = Math.toRadians(angle);
double x = this.getX() - aboutX; double x = this.x() - aboutX;
double z = this.getZ() - aboutZ; double z = this.z() - aboutZ;
double cos = Math.cos(angle); double cos = Math.cos(angle);
double sin = Math.sin(angle); double sin = Math.sin(angle);
double x2 = x * cos - z * sin; double x2 = x * cos - z * sin;
@ -609,7 +668,7 @@ public abstract class Vector3 {
return Vector3.at( return Vector3.at(
x2 + aboutX + translateX, x2 + aboutX + translateX,
getY(), y(),
z2 + aboutZ + translateZ z2 + aboutZ + translateZ
); );
} }
@ -621,16 +680,16 @@ public abstract class Vector3 {
* @return pitch in radians * @return pitch in radians
*/ */
public double toPitch() { public double toPitch() {
double x = getX(); double x = x();
double z = getZ(); double z = z();
if (x == 0 && z == 0) { if (x == 0 && z == 0) {
return getY() > 0 ? -90 : 90; return y() > 0 ? -90 : 90;
} else { } else {
double x2 = x * x; double x2 = x * x;
double z2 = z * z; double z2 = z * z;
double xz = Math.sqrt(x2 + z2); double xz = Math.sqrt(x2 + z2);
return Math.toDegrees(Math.atan(-getY() / xz)); return Math.toDegrees(Math.atan(-y() / xz));
} }
} }
@ -640,8 +699,8 @@ public abstract class Vector3 {
* @return yaw in radians * @return yaw in radians
*/ */
public double toYaw() { public double toYaw() {
double x = getX(); double x = x();
double z = getZ(); double z = z();
double t = Math.atan2(-x, z); double t = Math.atan2(-x, z);
double tau = 2 * Math.PI; double tau = 2 * Math.PI;
@ -658,9 +717,9 @@ public abstract class Vector3 {
//FAWE start - getter //FAWE start - getter
public Vector3 getMinimum(Vector3 v2) { public Vector3 getMinimum(Vector3 v2) {
return Vector3.at( return Vector3.at(
Math.min(getX(), v2.getX()), Math.min(x(), v2.x()),
Math.min(getY(), v2.getY()), Math.min(y(), v2.y()),
Math.min(getZ(), v2.getZ()) Math.min(z(), v2.z())
); );
} }
//FAWE end //FAWE end
@ -674,9 +733,9 @@ public abstract class Vector3 {
//FAWE start - getter //FAWE start - getter
public Vector3 getMaximum(Vector3 v2) { public Vector3 getMaximum(Vector3 v2) {
return Vector3.at( return Vector3.at(
Math.max(getX(), v2.getX()), Math.max(x(), v2.x()),
Math.max(getY(), v2.getY()), Math.max(y(), v2.y()),
Math.max(getZ(), v2.getZ()) Math.max(z(), v2.z())
); );
} }
//FAWE end //FAWE end
@ -700,7 +759,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public BlockVector3 toBlockPoint() { public BlockVector3 toBlockPoint() {
return toBlockPoint(getX(), getY(), getZ()); return toBlockPoint(x(), y(), z());
} }
//FAWE end //FAWE end
@ -711,24 +770,20 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public Vector2 toVector2() { public Vector2 toVector2() {
return Vector2.at(getX(), getZ()); return Vector2.at(x(), z());
} }
//FAWE end //FAWE end
//FAWE start - not a record, need own implementations
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof Vector3)) { if (!(obj instanceof final Vector3 other)) {
return false; return false;
} }
Vector3 other = (Vector3) obj; return other.x() == this.x() && other.y() == this.y() && other.z() == this.z();
//FAWE start - getter
return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ();
//FAWE end
} }
//FAWE start
/** /**
* Tests if vectors are equal, accounting for floating point errors * Tests if vectors are equal, accounting for floating point errors
* *
@ -741,28 +796,27 @@ public abstract class Vector3 {
} }
// Minecraft deals in whole blocks, thus any difference smaller than this is unnecessary // Minecraft deals in whole blocks, thus any difference smaller than this is unnecessary
if (Math.abs(getX() - other.getX()) > 0.000001d) { if (Math.abs(x() - other.x()) > 0.000001d) {
return false; return false;
} }
if (Math.abs(getY() - other.getY()) > 0.000001d) { if (Math.abs(y() - other.y()) > 0.000001d) {
return false; return false;
} }
return !(Math.abs(getZ() - other.getZ()) > 0.000001d); return !(Math.abs(z() - other.z()) > 0.000001d);
}
@Override
public int hashCode() {
return (int) x() ^ (int) z() << 12 ^ (int) y() << 24;
} }
//FAWE end //FAWE end
@Override
//FAWE start - XOR over get calculating all values independently
public int hashCode() {
return (int) getX() ^ (int) getZ() << 12 ^ (int) getY() << 24;
}
@Override @Override
public String toString() { public String toString() {
//FAWE start - getter & ternary //FAWE start - getter & ternary
String x = (getX() == getBlockX() ? "" + getBlockX() : "" + getX()); String x = (x() == blockX() ? "" + blockX() : "" + x());
String y = (getY() == getBlockY() ? "" + getBlockY() : "" + getY()); String y = (y() == blockY() ? "" + blockY() : "" + y());
String z = (getZ() == getBlockZ() ? "" + getBlockZ() : "" + getZ()); String z = (z() == blockZ() ? "" + blockZ() : "" + z());
//FAWE end //FAWE end
return "(" + x + ", " + y + ", " + z + ")"; return "(" + x + ", " + y + ", " + z + ")";
} }
@ -774,7 +828,7 @@ public abstract class Vector3 {
*/ */
//FAWE start - getter //FAWE start - getter
public String toParserString() { public String toParserString() {
return getX() + "," + getY() + "," + getZ(); return x() + "," + y() + "," + z();
} }
//FAWE end //FAWE end

View File

@ -302,11 +302,11 @@ public class Location extends Vector3Impl {
@Override @Override
public Location clampY(int min, int max) { public Location clampY(int min, int max) {
checkArgument(min <= max, "minimum cannot be greater than maximum"); checkArgument(min <= max, "minimum cannot be greater than maximum");
if (getY() < min) { if (y() < min) {
return new Location(extent, getX(), min, getZ()); return new Location(extent, x(), min, z());
} }
if (getY() > max) { if (y() > max) {
return new Location(extent, getX(), max, getZ()); return new Location(extent, x(), max, z());
} }
return this; return this;
@ -331,13 +331,13 @@ public class Location extends Vector3Impl {
return false; return false;
} }
//FAWE start //FAWE start
if (this.getX() != location.getX()) { if (this.x() != location.x()) {
return false; return false;
} }
if (this.getZ() != location.getZ()) { if (this.z() != location.z()) {
return false; return false;
} }
if (this.getY() != location.getY()) { if (this.y() != location.y()) {
return false; return false;
} }
return extent.equals(location.extent); return extent.equals(location.extent);