Fix minetestmapper.py
authorPerttu Ahola <celeron55@gmail.com>
Mon, 26 Sep 2011 17:54:42 +0000 (20:54 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 26 Sep 2011 18:57:18 +0000 (21:57 +0300)
util/minetestmapper.py

index c7ec0774ecae81b606ab8009b12cc1fad16c0c14..1914576e8859a965f718f374a7ec9262e7007b28 100755 (executable)
@@ -88,9 +88,19 @@ def int_to_hex4(i):
 def getBlockAsInteger(p):
     return p[2]*16777216 + p[1]*4096 + p[0]
 
-def getIntegerAsBlock(i):
-    return i%4096, int(i/4096)%4096, int(i/16777216)%4096
+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 limit(i, l, h):
     if(i > h):