diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/components/location/BlockPositionGet.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/components/location/BlockPositionGet.java index 5a464fa7..18034574 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/components/location/BlockPositionGet.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/components/location/BlockPositionGet.java @@ -1,7 +1,11 @@ package fr.neatmonster.nocheatplus.components.location; +import fr.neatmonster.nocheatplus.utilities.ds.map.CoordHash; + /** - * Simple immutable block position. + * Simple immutable block position. Both hashCode and equals are implemented, + * with equals accepting any IGetBlockPosition instance for comparison of block + * coordinates. * * @author asofold * @@ -33,6 +37,21 @@ public class BlockPositionGet implements IGetBlockPosition { return z; } - // TODO: equals vs. IGetBlockPosition, Coord(Hash)Map compatible hashCode. + @Override + public int hashCode() { + return CoordHash.hashCode3DPrimes(x, y, z); + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (obj instanceof IGetBlockPosition) { + final IGetBlockPosition other = (IGetBlockPosition) obj; + return x == other.getBlockX() && y == other.getBlockY() && z == other.getBlockZ(); + } + return false; + } }