def process_region_file(filename, start, stop): """Given a region filename, return the number of blocks of each ID in that file""" pieces = filename.split('.') rx = int(pieces[-3]) rz = int(pieces[-2]) block_data_totals = [[0]*16 for i in range(256)] # up to 16 data numbers in 256 block IDs # Does the region overlap the bounding box at all? if (start != None): selectLowX = int(start[0]) selectLowZ = int(start[2]) zoneHiX = (rx+1)*512-1 # accorping to placement on world coordinate system zoneHiZ = (rz+1)*512-1 if ( zoneHiX < selectLowX or zoneHiZ < selectLowZ ): return block_data_totals elif (stop != None): selectHiX = int(stop[0]) selectHiZ = int(stop[2]) zoneLowX = rx*512 zoneLowZ = rz*512 if ( zoneLowX > selectHiX or zoneLowZ > selectHiZ ): return block_data_totals file = RegionFile(filename) # Get all chunks chunks = file.get_chunks() print("Parsing %s... %d chunks" % (os.path.basename(filename),len(chunks))) for c in chunks: # Does the chunk overlap the bounding box at all? if (start != None): chunkHiX = rx*512 + ( (c['x']+1)*16 - 1) chunkHiZ = rz*512 + ( c['z']*16 - 1) selectLowX = int(start[0]) selectLowZ = int(start[2]) if ( chunkHiX < selectLowX or chunkHiZ < selectLowZ ): continue elif (stop != None): chunkLowX = rx*512 + c['x']*16 chunkLowZ = rz*512 + c['z']*16 selectHiX = int(stop[0]) selectHiZ = int(stop[2]) if ( chunkLowX > selectHiX or chunkLowZ > selectHiZ ): continue chunk = Chunk(file.get_chunk(c['x'], c['z'])) assert chunk.get_coords() == (c['x'] + rx*32, c['z'] + rz*32) #print("Parsing chunk ("+str(c['x'])+", "+str(c['z'])+")") # Parse the blocks # Fast code if no start or stop coordinates are specified # TODO: also use this code if start/stop is specified, but the complete chunk is included if (start == None and stop == None): stats_per_chunk(chunk, block_data_totals) else: # Slow code that iterates through each coordinate bounded_stats_per_chunk(chunk, block_data_totals, start, stop) return block_data_totals
def process_region_file(filename, start, stop): """Given a region filename, return the number of blocks of each ID in that file""" pieces = filename.split('.') rx = int(pieces[1]) rz = int(pieces[2]) block_data_totals = [[0] * 16 for i in range(256) ] # up to 16 data numbers in 256 block IDs # Does the region overlap the bounding box at all? if (start != None): if ((rx + 1) * 512 - 1 < int(start[0]) or (rz + 1) * 512 - 1 < int(start[2])): return block_data_totals elif (stop != None): if (rx * 512 - 1 > int(stop[0]) or rz * 512 - 1 > int(stop[2])): return block_data_totals file = RegionFile(filename) # Get all chunks chunks = file.get_chunks() print("Parsing %s... %d chunks" % (os.path.basename(filename), len(chunks))) for c in chunks: # Does the chunk overlap the bounding box at all? if (start != None): if ((c['x'] + 1) * 16 + rx * 512 - 1 < int(start[0]) or (c['z'] + 1) * 16 + rz * 512 - 1 < int(start[2])): continue elif (stop != None): if (c['x'] * 16 + rx * 512 - 1 > int(stop[0]) or c['z'] * 16 + rz * 512 - 1 > int(stop[2])): continue chunk = Chunk(file.get_chunk(c['x'], c['z'])) assert chunk.get_coords() == (c['x'] + rx * 32, c['z'] + rz * 32) #print("Parsing chunk ("+str(c['x'])+", "+str(c['z'])+")") # Parse the blocks # Fast code if no start or stop coordinates are specified # TODO: also use this code if start/stop is specified, but the complete chunk is included if (start == None and stop == None): stats_per_chunk(chunk, block_data_totals) else: # Slow code that iterates through each coordinate bounded_stats_per_chunk(chunk, block_data_totals, start, stop) return block_data_totals
def process_region_file(filename, start, stop): """Given a region filename, return the number of blocks of each ID in that file""" pieces = filename.split('.') rx = int(pieces[1]) rz = int(pieces[2]) block_data_totals = [[0]*16 for i in range(256)] # up to 16 data numbers in 256 block IDs # Does the region overlap the bounding box at all? if (start != None): if ( (rx+1)*512-1 < int(start[0]) or (rz+1)*512-1 < int(start[2]) ): return block_data_totals elif (stop != None): if ( rx*512-1 > int(stop[0]) or rz*512-1 > int(stop[2]) ): return block_data_totals file = RegionFile(filename) # Get all chunks chunks = file.get_chunks() print("Parsing %s... %d chunks" % (os.path.basename(filename),len(chunks))) for c in chunks: # Does the chunk overlap the bounding box at all? if (start != None): if ( (c['x']+1)*16 + rx*512 - 1 < int(start[0]) or (c['z']+1)*16 + rz*512 - 1 < int(start[2]) ): continue elif (stop != None): if ( c['x']*16 + rx*512 - 1 > int(stop[0]) or c['z']*16 + rz*512 - 1 > int(stop[2]) ): continue chunk = Chunk(file.get_chunk(c['x'], c['z'])) assert chunk.get_coords() == (c['x'] + rx*32, c['z'] + rz*32) #print("Parsing chunk ("+str(c['x'])+", "+str(c['z'])+")") # Parse the blocks # Fast code if no start or stop coordinates are specified # TODO: also use this code if start/stop is specified, but the complete chunk is included if (start == None and stop == None): stats_per_chunk(chunk, block_data_totals) else: # Slow code that iterates through each coordinate bounded_stats_per_chunk(chunk, block_data_totals, start, stop) return block_data_totals
def __init__(self, filename): print "Processing region file " + filename colormap = BlockColorMap() file = open(regionPath + filename, 'rb') region = RegionFile(fileobj=file) img = Image.new('RGBA', (32 * 16, 32 * 16)) for c in region.get_chunks(): cx = c['x'] cz = c['z'] chunk = Chunk(region, cx, cz) if chunk.status != 'postprocessed': continue for x in range(0, 16): for z in range(0, 16): col = chunk.getColumnInfo(x, z) color = colormap.getColor(col) img.putpixel((cx * 16 + x, cz * 16 + z), color) img.save(outputPath + filename + ".png") file.close()
pieces = filename.split('.') rx = int(pieces[1]) rz = int(pieces[2]) # Does the region overlap the bounding box at all? if (start != None): if ( (rx+1)*512-1 < int(start[0]) or (rz+1)*512-1 < int(start[2]) ): continue elif (stop != None): if ( rx*512-1 > int(stop[0]) or rz*512-1 > int(stop[2]) ): continue file = RegionFile(filename=world_folder+'/region/'+filename) # Get all chunks chunks = file.get_chunks() for c in chunks: # Does the chunk overlap the bounding box at all? if (start != None): if ( (c['x']+1)*16 + rx*512 - 1 < int(start[0]) or (c['z']+1)*16 + rz*512 - 1 < int(start[2]) ): continue elif (stop != None): if ( c['x']*16 + rx*512 - 1 > int(stop[0]) or c['z']*16 + rz*512 - 1 > int(stop[2]) ): continue chunk = Chunk(file.get_chunk(c['x'], c['z'])) #print "Parsing chunk ("+str(c['x'])+", "+str(c['z'])+")" # Parse the blocks # Fast code if no start or stop coordinates are specified