mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-06-26 06:14:42 +02:00
Implement equals and hashCode for BlockPositionGet.
This commit is contained in:
parent
087d800de4
commit
bd68362197
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user