original_docstring: Scan a world for dungeons. Try to cache the results and only look at
      chunks that have changed since the last run.
docstring: Scan a world for dungeons. Try to cache the results and only look at
  chunks that have changed since the last run.
docstring_tokens: Scan a world for dungeons . Try to cache the results and only look at chunks that have changed since the last run .
code: 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
code_tokens: def listDungeons ( world , oworld , expand_fill_caves = False ) : global cache_path pm = pmeter . ProgressMeter ( ) dungeonCacheOld , mtime = utils . loadDungeonCache ( cache_path ) dungeonCache = { } 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 ) 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
short_docstring: Scan a world for dungeons.
short_docstring_tokens: Scan a world for dungeons .
comment: '''Scan a world for dungeons. Try to cache the results and only look at
      chunks that have changed since the last run.'''$SEP$# Try to load the cache$SEP$# Scan with overviewer$SEP$# Process the dungeons