block packet API

This commit is contained in:
FalsePattern committed 2024-11-16 23:07:36 +01:00
1 parent a91a79c0e2
commit 83d2509ccc
15 files changed
+482 -18

No files matched your search

@@ -0,0 +1,28 @@
package com.falsepattern.chunk.internal;
public class BlockPosUtil {
private static final int NUM_X_BITS = 26;
private static final int NUM_Z_BITS = 26;
private static final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS;
private static final long Y_MASK = (1L << NUM_Y_BITS) - 1L;
private static final int Y_SHIFT = NUM_Z_BITS;
private static final int X_SHIFT = Y_SHIFT + NUM_Y_BITS;
private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L;
private static final long X_MASK = (1L << NUM_X_BITS) - 1L;
public static long packToLong(int x, int y, int z) {
return ((long) x & X_MASK) << X_SHIFT | ((long) y & Y_MASK) << Y_SHIFT | ((long) z & Z_MASK);
}
public static int getX(long packed) {
return (int) (packed << 64 - X_SHIFT - NUM_X_BITS >> 64 - NUM_X_BITS);
}
public static int getY(long packed) {
return (int) (packed << 64 - Y_SHIFT - NUM_Y_BITS >> 64 - NUM_Y_BITS);
}
public static int getZ(long packed) {
return (int) (packed << 64 - NUM_Z_BITS >> 64 - NUM_Z_BITS);
}
}