added CompactedCoords util
This commit is contained in:
23
core/src/main/java/mc/core/utils/CompactedCoords.java
Normal file
23
core/src/main/java/mc/core/utils/CompactedCoords.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package mc.core.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class CompactedCoords {
|
||||
public static int compressXZ(int x, int z) {
|
||||
if (x < Short.MIN_VALUE || x > Short.MAX_VALUE ||
|
||||
z < Short.MIN_VALUE || z > Short.MAX_VALUE) {
|
||||
log.warn("Coord over range: [{},{}]", x, z);
|
||||
}
|
||||
|
||||
return ((x & 0xFFFF) << 16) | (z & 0xFFFF);
|
||||
}
|
||||
|
||||
public static int[] uncompressXZ(int compactValue) {
|
||||
//TODO не нравится мне такие костыли
|
||||
return new int[]{
|
||||
(int)(short) (compactValue >> 16),
|
||||
(int)(short) (compactValue | 0xFFFF0000)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user