From 58ca2024e1567a0017f6f12583ea8ff75846bb63 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 6 Nov 2023 20:17:42 +1000 Subject: [PATCH] Add static chunkKey method in ChunkPosition --- .../api/minecraft/metadata/ChunkPosition.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/ChunkPosition.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/ChunkPosition.java index 7098d676e..cffafb71f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/ChunkPosition.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/ChunkPosition.java @@ -28,12 +28,12 @@ public final class ChunkPosition { private final int chunkX; private final int chunkZ; - public ChunkPosition(int chunkX, int chunkZ) { + public ChunkPosition(final int chunkX, final int chunkZ) { this.chunkX = chunkX; this.chunkZ = chunkZ; } - public ChunkPosition(long chunkKey) { + public ChunkPosition(final long chunkKey) { this.chunkX = (int) chunkKey; this.chunkZ = (int) (chunkKey >> 32); } @@ -46,15 +46,31 @@ public final class ChunkPosition { return chunkZ; } + /** + * Returns a long key for this chunk position. + * + * @return the chunk key + */ public long chunkKey() { + return chunkKey(chunkX, chunkZ); + } + + /** + * Returns a long key for the given chunk coordinates. + * + * @param chunkX the chunk X coordinate + * @param chunkZ the chunk Z coordinate + * @return the chunk key + */ + public static long chunkKey(final int chunkX, final int chunkZ) { return (long) chunkX & 0xffffffffL | ((long) chunkZ & 0xffffffffL) << 32; } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ChunkPosition that = (ChunkPosition) o; + final ChunkPosition that = (ChunkPosition) o; return chunkX == that.chunkX && chunkZ == that.chunkZ; }