def listDungeons(world, oworld, expand_fill_caves=False): '''Scan a world for dungeons. Try to cache the results and only look at chunks that have changed since the last run.''' global cache_path pm = pmeter.ProgressMeter() # Try to load the cache dungeonCacheOld, mtime = utils.loadDungeonCache(cache_path) dungeonCache = {} # Scan with overviewer regions = oworld.get_regionset(None) count = world.chunkCount cached = 0 notcached = 0 print 'Scanning world for existing dungeons:' print 'cache mtime: %d' % (mtime) pm.init(count, label='') for cx, cz, cmtime in regions.iterate_chunks(): count -= 1 pm.update_left(count) key = '%s,%s' % (cx*16, cz*16) if (cmtime > mtime or key in dungeonCacheOld): notcached += 1 for tileEntity in regions.get_chunk(cx, cz)["TileEntities"]: if ( tileEntity['id'] == 'Sign' and tileEntity['Text1'].startswith('[MCD]') ): key = '%s,%s' % (tileEntity["x"], tileEntity["z"]) dungeonCache[key] = tileEntity if ( tileEntity['id'] == 'Chest' and 'CustomName' in tileEntity and tileEntity['CustomName'] == 'MCDungeon Data Library' ): key = '%s,%s' % (tileEntity["x"], tileEntity["z"]) dungeonCache[key] = tileEntity else: cached += 1 continue pm.set_complete() print ' Cache hit rate: %d/%d (%d%%)' % (cached, world.chunkCount, 100*cached/world.chunkCount) utils.saveDungeonCache(cache_path, dungeonCache) # Process the dungeons dungeons = [] output = '' output += "Known dungeons on this map:\n" output += '+-----------+----------------+---------+-------+----+'\ '-------------------------+\n' output += '| %9s | %14s | %7s | %5s | %2s | %23s |\n' % ( 'Pos', 'Date/Time', 'Ver', 'Size', 'Lv', 'Name' ) output += '+-----------+----------------+---------+-------+----+'\ '-------------------------+\n' for tileEntity in dungeonCache.values(): info = utils.decodeDungeonInfo(tileEntity) (major, minor, patch) = info['version'].split('.') version = float(major+'.'+minor) xsize = info['xsize'] zsize = info['zsize'] levels = info['levels'] offset = 0 if ( expand_fill_caves is True and info['fill_caves'] is True ): offset = 5 dungeons.append((info["position"].x-offset, info["position"].z-offset, xsize+offset, zsize+offset, info, levels, info["position"].x, info["position"].y, info["position"].z, version)) output += '| %9s | %14s | %7s | %5s | %2d | %23s |\n' % ( '%d %d' % (info["position"].x, info["position"].z), time.strftime('%x %H:%M', time.localtime(info['timestamp'])), info['version'], '%dx%d' % (xsize, zsize), levels, info.get('full_name', 'Dungeon')[:23] ) output += '+-----------+----------------+---------+-------+----+'\ '-------------------------+\n' if len(dungeons) > 0: print output else: print 'No dungeons found!' return dungeons
chunks.append((p[0]+x, p[1]+z)) # We need to update the caches for the chunks we are affecting ccache, cmtime = utils.loadChunkCache(cache_path) # Delete the chunks for c in chunks: if world.containsChunk(c[0], c[1]): world.deleteChunk(c[0], c[1]) ckey = '%s,%s' % (c[0], c[1]) if ckey in ccache: del ccache[ckey] else: print 'WARN: Chunk not in chunk cache! '+ckey # Save the world. print "Saving..." world.saveInPlace() utils.saveDungeonCache(cache_path, dcache) utils.saveChunkCache(cache_path, ccache) sys.exit() # Regenerate mode if (args.command == 'regenerate'): # Check to make sure the user specified what they want to do. if args.dungeons == [] and args.all is False: print 'You must specify either --all or at least one -d option when ' \ 'regnerating dungeons.' sys.exit(1) # Get a list of known dungeons and their size. if dungeons == []: dungeons = listDungeons(world, oworld) # No dungeons. Exit. if len(dungeons) == 0: