def block_breakdown(worlddir): """Analyzes the given world dir and tallys up total block counts for each type. Returns two arrays. The first is a mapping from (blocktype, z-height) to count The second is a mapping from blocktype to total count """ # Maps (blocktype, z-height) to count heights = zeros((256,128), dtype=int) # Maps (blocktype) to total totals = zeros((256,), dtype=int) all_chunks = world.find_chunkfiles(worlddir) for i, (chunkx, chunky, chunkfile) in enumerate(all_chunks): print "{0} / {1}".format(i, len(all_chunks)) sys.stdout.flush() blockarr = chunk.get_blockarray_fromfile(chunkfile) for coord, blocktype in ndenumerate(blockarr): totals[blocktype] += 1 heights[blocktype, coord[2]] += 1 return heights, totals
def block_breakdown(worlddir): """Analyzes the given world dir and tallys up total block counts for each type. Returns two arrays. The first is a mapping from (blocktype, z-height) to count The second is a mapping from blocktype to total count """ # Maps (blocktype, z-height) to count heights = zeros((256, 128), dtype=int) # Maps (blocktype) to total totals = zeros((256, ), dtype=int) all_chunks = world.find_chunkfiles(worlddir) for i, (chunkx, chunky, chunkfile) in enumerate(all_chunks): print "{0} / {1}".format(i, len(all_chunks)) sys.stdout.flush() blockarr = chunk.get_blockarray_fromfile(chunkfile) for coord, blocktype in ndenumerate(blockarr): totals[blocktype] += 1 heights[blocktype, coord[2]] += 1 return heights, totals
import os import re parser = OptionParser() parser.add_option("--ids", dest="ids", type="string") parser.add_option("--world", dest="world", type="string") options, args = parser.parse_args() if not options.world or not options.ids: parser.print_help() sys.exit(1) if not os.path.exists(options.world): raise Exception("%s does not exist" % options.world) ids = map(lambda x: int(x), options.ids.split(",")) sys.stderr.write("Searching for these blocks: %r...\n" % ids) matcher = re.compile(r"^c\..*\.dat$") for dirpath, dirnames, filenames in os.walk(options.world): for f in filenames: if matcher.match(f): full = os.path.join(dirpath, f) blocks = get_blockarray_fromfile(full) for i in ids: if i in blocks: print full break
parser = OptionParser() parser.add_option("--ids", dest="ids", type="string") parser.add_option("--world", dest="world", type="string") options, args = parser.parse_args() if not options.world or not options.ids: parser.print_help() sys.exit(1) if not os.path.exists(options.world): raise Exception("%s does not exist" % options.world) ids = map(lambda x: int(x),options.ids.split(",")) sys.stderr.write("Searching for these blocks: %r...\n" % ids) matcher = re.compile(r"^c\..*\.dat$") for dirpath, dirnames, filenames in os.walk(options.world): for f in filenames: if matcher.match(f): full = os.path.join(dirpath, f) blocks = get_blockarray_fromfile(full) for i in ids: if i in blocks: print full break