Archived
0

added CompactedCoords util

This commit is contained in:
2018-08-12 23:37:48 +03:00
parent b8a71c070c
commit d4785cda14
2 changed files with 68 additions and 0 deletions

View 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)
};
}
}