2012-12-31 05:15:40 -08:00
|
|
|
def getBlockAsInteger(x, y, z):
|
|
|
|
return z * 16777216 + y * 4096 + x
|
|
|
|
|
|
|
|
|
2012-12-30 10:50:35 -08:00
|
|
|
def unsignedToSigned(i, max_positive):
|
|
|
|
if i < max_positive:
|
|
|
|
return i
|
|
|
|
else:
|
|
|
|
return i - 2 * max_positive
|
|
|
|
|
|
|
|
|
2012-12-31 05:15:40 -08:00
|
|
|
def getIntegerAsBlock(i):
|
|
|
|
x = unsignedToSigned(i % 4096, 2048)
|
|
|
|
i = int((i - x) / 4096)
|
|
|
|
y = unsignedToSigned(i % 4096, 2048)
|
|
|
|
i = int((i - y) / 4096)
|
|
|
|
z = unsignedToSigned(i % 4096, 2048)
|
|
|
|
return x,y,z
|
|
|
|
|
|
|
|
|
2012-12-30 10:06:11 -08:00
|
|
|
def readU8(f):
|
|
|
|
return ord(f.read(1))
|
|
|
|
|
|
|
|
|
|
|
|
def readU16(f):
|
|
|
|
return ord(f.read(1)) * 256 + ord(f.read(1))
|
|
|
|
|
|
|
|
|
|
|
|
def readU32(f):
|
|
|
|
return ord(f.read(1)) * 256 * 256 * 256 + ord(f.read(1)) * 256 * 256 + ord(f.read(1)) * 256 + ord(f.read(1))
|
|
|
|
|
|
|
|
|
|
|
|
def readS32(f):
|
|
|
|
return unsignedToSigned(ord(f.read(1)) * 256 * 256 * 256 + ord(f.read(1)) * 256 * 256 + ord(f.read(1)) * 256 + ord(f.read(1)), 2 ** 31)
|
2012-12-31 05:15:40 -08:00
|
|
|
|
|
|
|
|
|
|
|
def gridToCoords(row, col):
|
2020-10-21 18:01:27 -07:00
|
|
|
return (row - col) // 2, (row + col) // 2
|
2012-12-31 05:15:40 -08:00
|
|
|
|
|
|
|
|
|
|
|
def coordsToGrid(x, z):
|
|
|
|
return x + z, z - x
|