forked from HybridDog/onomatopoeia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
42 lines (26 loc) · 949 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def getBlockAsInteger(x, y, z):
return z * 16777216 + y * 4096 + x
def unsignedToSigned(i, max_positive):
if i < max_positive:
return i
else:
return i - 2 * max_positive
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
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)
def gridToCoords(row, col):
return (row - col) // 2, (row + col) // 2
def coordsToGrid(x, z):
return x + z, z - x