- #if n > 500:
- # break
- if n % 200 == 0:
- nowtime = time.time()
- dtime = nowtime - starttime
- try:
- n_per_second = 1.0 * n / dtime
- except ZeroDivisionError:
- n_per_second = 0
- if n_per_second != 0:
- seconds_per_n = 1.0 / n_per_second
- time_guess = seconds_per_n * len(xlist)
- remaining_s = time_guess - dtime
- remaining_minutes = int(remaining_s / 60)
- remaining_s -= remaining_minutes * 60;
- print("Processing sector "+str(n)+" of "+str(len(xlist))
- +" ("+str(round(100.0*n/len(xlist), 1))+"%)"
- +" (ETA: "+str(remaining_minutes)+"m "
- +str(int(remaining_s))+"s)")
-
- xpos = xlist[n]
- zpos = zlist[n]
-
- xhex = int_to_hex3(xpos)
- zhex = int_to_hex3(zpos)
- xhex4 = int_to_hex4(xpos)
- zhex4 = int_to_hex4(zpos)
-
- sector1 = xhex4.lower() + zhex4.lower()
- sector2 = xhex.lower() + "/" + zhex.lower()
-
- ylist = []
-
- sectortype = ""
-
- try:
- for filename in os.listdir(path + "sectors/" + sector1):
- if(filename != "meta"):
- pos = int(filename, 16)
- if(pos > 32767):
- pos -= 65536
- ylist.append(pos)
- sectortype = "old"
- except OSError:
- pass
-
- if sectortype != "old":
- try:
- for filename in os.listdir(path + "sectors2/" + sector2):
- if(filename != "meta"):
- pos = int(filename, 16)
- if(pos > 32767):
- pos -= 65536
- ylist.append(pos)
- sectortype = "new"
- except OSError:
- pass
-
- if sectortype == "":
- continue
-
- ylist.sort()
-
- # Make a list of pixels of the sector that are to be looked for.
- pixellist = []
- water = {}
- for x in range(16):
- for z in range(16):
- pixellist.append((x, z))
- water[(x, z)] = 0
-
- # Go through the Y axis from top to bottom.
- ylist2=[]
- for ypos in reversed(ylist):
-
- yhex = int_to_hex4(ypos)
-
- filename = ""
- if sectortype == "old":
- filename = path + "sectors/" + sector1 + "/" + yhex.lower()
- else:
- filename = path + "sectors2/" + sector2 + "/" + yhex.lower()
-
- f = file(filename, "rb")
-
- version = f.read(1)
- flags = f.read(1)
-
- # Checking day and night differs -flag
- if not ord(flags) & 2:
- ylist2.append((ypos,filename))
- f.close()
- continue
-
- dec_o = zlib.decompressobj()
- try:
- mapdata = dec_o.decompress(f.read())
- except:
- mapdata = []
-
- f.close()
-
- if(len(mapdata) < 4096):
- print "bad: " + xhex + "/" + zhex + "/" + yhex + " " + str(len(mapdata))
- else:
- chunkxpos = xpos * 16
- chunkypos = ypos * 16
- chunkzpos = zpos * 16
- for (x, z) in reversed(pixellist):
- for y in reversed(range(16)):
- datapos = x + y * 16 + z * 256
- if(ord(mapdata[datapos]) != 254 and ord(mapdata[datapos]) in colors):
- if(ord(mapdata[datapos]) == 2 or ord(mapdata[datapos]) == 9):
- water[(x, z)] += 1
- # Add dummy stuff for drawing sea without seabed
- stuff[(chunkxpos + x, chunkzpos + z)] = (chunkypos + y, ord(mapdata[datapos]), water[(x, z)])
- else:
- pixellist.remove((x, z))
- # Memorize information on the type and height of the block and for drawing the picture.
- stuff[(chunkxpos + x, chunkzpos + z)] = (chunkypos + y, ord(mapdata[datapos]), water[(x, z)])
- break
- elif(ord(mapdata[datapos]) != 254 and ord(mapdata[datapos]) not in colors):
- print "strange block: " + xhex + "/" + zhex + "/" + yhex + " x: " + str(x) + " y: " + str(y) + " z: " + str(z) + " palikka: " + str(ord(mapdata[datapos]))
-
- # After finding all the pixels in the sector, we can move on to the next sector without having to continue the Y axis.
- if(len(pixellist) == 0):
- break
-
- if len(pixellist) > 0:
- for (ypos, filename) in ylist2:
- f = file(filename, "rb")
-
- version = f.read(1)
- flags = f.read(1)
-
- dec_o = zlib.decompressobj()
- try:
- mapdata = dec_o.decompress(f.read())
- except:
- mapdata = []
-
- f.close()
-
- if(len(mapdata) < 4096):
- print "bad: " + xhex + "/" + zhex + "/" + yhex + " " + str(len(mapdata))
- else:
- chunkxpos = xpos * 16
- chunkypos = ypos * 16
- chunkzpos = zpos * 16
- for (x, z) in reversed(pixellist):
- for y in reversed(range(16)):
- datapos = x + y * 16 + z * 256
- if(ord(mapdata[datapos]) != 254 and ord(mapdata[datapos]) in colors):
- if(ord(mapdata[datapos]) == 2 or ord(mapdata[datapos]) == 9):
- water[(x, z)] += 1
- # Add dummy stuff for drawing sea without seabed
- stuff[(chunkxpos + x, chunkzpos + z)] = (chunkypos + y, ord(mapdata[datapos]), water[(x, z)])
- else:
- pixellist.remove((x, z))
- # Memorize information on the type and height of the block and for drawing the picture.
- stuff[(chunkxpos + x, chunkzpos + z)] = (chunkypos + y, ord(mapdata[datapos]), water[(x, z)])
- break
- elif(ord(mapdata[datapos]) != 254 and ord(mapdata[datapos]) not in colors):
- print "outo palikka: " + xhex + "/" + zhex + "/" + yhex + " x: " + str(x) + " y: " + str(y) + " z: " + str(z) + " palikka: " + str(ord(mapdata[datapos]))
-
- # After finding all the pixels in the sector, we can move on to the next sector without having to continue the Y axis.
- if(len(pixellist) == 0):
- break
-
-print "Drawing image"
+ #if n > 500:
+ # break
+ if n % 200 == 0:
+ nowtime = time.time()
+ dtime = nowtime - starttime
+ try:
+ n_per_second = 1.0 * n / dtime
+ except ZeroDivisionError:
+ n_per_second = 0
+ if n_per_second != 0:
+ seconds_per_n = 1.0 / n_per_second
+ time_guess = seconds_per_n * len(xlist)
+ remaining_s = time_guess - dtime
+ remaining_minutes = int(remaining_s / 60)
+ remaining_s -= remaining_minutes * 60
+ print("Processing sector " + str(n) + " of " + str(len(xlist))
+ + " (" + str(round(100.0 * n / len(xlist), 1)) + "%)"
+ + " (ETA: " + str(remaining_minutes) + "m "
+ + str(int(remaining_s)) + "s)")
+
+ xpos = xlist[n]
+ zpos = zlist[n]
+
+ xhex = int_to_hex3(xpos)
+ zhex = int_to_hex3(zpos)
+ xhex4 = int_to_hex4(xpos)
+ zhex4 = int_to_hex4(zpos)
+
+ sector1 = xhex4.lower() + zhex4.lower()
+ sector2 = xhex.lower() + "/" + zhex.lower()
+
+ ylist = []
+
+ sectortype = ""
+
+ if cur:
+ psmin = getBlockAsInteger((xpos, -2048, zpos))
+ psmax = getBlockAsInteger((xpos, 2047, zpos))
+ cur.execute("SELECT `pos` FROM `blocks` WHERE `pos`>=? AND `pos`<=? AND (`pos` - ?) % 4096 = 0", (psmin, psmax, psmin))
+ while True:
+ r = cur.fetchone()
+ if not r:
+ break
+ pos = getIntegerAsBlock(r[0])[1]
+ ylist.append(pos)
+ sectortype = "sqlite"
+ try:
+ for filename in os.listdir(path + "sectors/" + sector1):
+ if(filename != "meta"):
+ pos = int(filename, 16)
+ if(pos > 32767):
+ pos -= 65536
+ ylist.append(pos)
+ sectortype = "old"
+ except OSError:
+ pass
+
+ if sectortype == "":
+ try:
+ for filename in os.listdir(path + "sectors2/" + sector2):
+ if(filename != "meta"):
+ pos = int(filename, 16)
+ if(pos > 32767):
+ pos -= 65536
+ ylist.append(pos)
+ sectortype = "new"
+ except OSError:
+ pass
+
+ if sectortype == "":
+ continue
+
+ ylist.sort()
+
+ # Make a list of pixels of the sector that are to be looked for.
+ pixellist = []
+ water = {}
+ for x in range(16):
+ for z in range(16):
+ pixellist.append((x, z))
+ water[(x, z)] = 0
+
+ # Go through the Y axis from top to bottom.
+ for ypos in reversed(ylist):
+ try:
+ #print("("+str(xpos)+","+str(ypos)+","+str(zpos)+")")
+
+ yhex = int_to_hex4(ypos)
+
+ if sectortype == "sqlite":
+ ps = getBlockAsInteger((xpos, ypos, zpos))
+ cur.execute("SELECT `data` FROM `blocks` WHERE `pos`==? LIMIT 1", (ps,))
+ r = cur.fetchone()
+ if not r:
+ continue
+ f = cStringIO.StringIO(r[0])
+ else:
+ if sectortype == "old":
+ filename = path + "sectors/" + sector1 + "/" + yhex.lower()
+ else:
+ filename = path + "sectors2/" + sector2 + "/" + yhex.lower()
+ f = file(filename, "rb")
+
+ # Let's just memorize these even though it's not really necessary.
+ version = readU8(f)
+ flags = f.read(1)
+
+ #print("version="+str(version))
+ #print("flags="+str(version))
+
+ # Check flags
+ is_underground = ((ord(flags) & 1) != 0)
+ day_night_differs = ((ord(flags) & 2) != 0)
+ lighting_expired = ((ord(flags) & 4) != 0)
+ generated = ((ord(flags) & 8) != 0)
+
+ #print("is_underground="+str(is_underground))
+ #print("day_night_differs="+str(day_night_differs))
+ #print("lighting_expired="+str(lighting_expired))
+ #print("generated="+str(generated))
+
+ if version >= 22:
+ content_width = readU8(f)
+ params_width = readU8(f)
+
+ # Node data
+ dec_o = zlib.decompressobj()
+ try:
+ mapdata = array.array("B", dec_o.decompress(f.read()))
+ except:
+ mapdata = []
+
+ # Reuse the unused tail of the file
+ f.close();
+ f = cStringIO.StringIO(dec_o.unused_data)
+ #print("unused data: "+repr(dec_o.unused_data))
+
+ # zlib-compressed node metadata list
+ dec_o = zlib.decompressobj()
+ try:
+ metaliststr = array.array("B", dec_o.decompress(f.read()))
+ # And do nothing with it
+ except:
+ metaliststr = []
+
+ # Reuse the unused tail of the file
+ f.close();
+ f = cStringIO.StringIO(dec_o.unused_data)
+ #print("* dec_o.unused_data: "+repr(dec_o.unused_data))
+ data_after_node_metadata = dec_o.unused_data
+
+ if version <= 21:
+ # mapblockobject_count
+ readU16(f)
+
+ if version == 23:
+ readU8(f) # Unused node timer version (always 0)
+ if version == 24:
+ ver = readU8(f)
+ if ver == 1:
+ num = readU16(f)
+ for i in range(0,num):
+ readU16(f)
+ readS32(f)
+ readS32(f)
+
+ static_object_version = readU8(f)
+ static_object_count = readU16(f)
+ for i in range(0, static_object_count):
+ # u8 type (object type-id)
+ object_type = readU8(f)
+ # s32 pos_x_nodes * 10000
+ pos_x_nodes = readS32(f)/10000
+ # s32 pos_y_nodes * 10000
+ pos_y_nodes = readS32(f)/10000
+ # s32 pos_z_nodes * 10000
+ pos_z_nodes = readS32(f)/10000
+ # u16 data_size
+ data_size = readU16(f)
+ # u8[data_size] data
+ data = f.read(data_size)
+
+ timestamp = readU32(f)
+ #print("* timestamp="+str(timestamp))
+
+ id_to_name = {}
+ if version >= 22:
+ name_id_mapping_version = readU8(f)
+ num_name_id_mappings = readU16(f)
+ #print("* num_name_id_mappings: "+str(num_name_id_mappings))
+ for i in range(0, num_name_id_mappings):
+ node_id = readU16(f)
+ name_len = readU16(f)
+ name = f.read(name_len)
+ #print(str(node_id)+" = "+name)
+ id_to_name[node_id] = name
+
+ # Node timers
+ if version >= 25:
+ timer_size = readU8(f)
+ num = readU16(f)
+ for i in range(0,num):
+ readU16(f)
+ readS32(f)
+ readS32(f)
+
+ read_mapdata(mapdata, version, pixellist, water, day_night_differs, id_to_name)
+
+ # After finding all the pixels in the sector, we can move on to
+ # the next sector without having to continue the Y axis.
+ if(len(pixellist) == 0):
+ break
+ except Exception as e:
+ print("Error at ("+str(xpos)+","+str(ypos)+","+str(zpos)+"): "+str(e))
+ sys.stdout.write("Block data: ")
+ for c in r[0]:
+ sys.stdout.write("%2.2x "%ord(c))
+ sys.stdout.write(os.linesep)
+ sys.stdout.write("Data after node metadata: ")
+ for c in data_after_node_metadata:
+ sys.stdout.write("%2.2x "%ord(c))
+ sys.stdout.write(os.linesep)
+ traceback.print_exc()
+
+print("Drawing image")