<s> """<STR_LIT>""" <EOL> import locale , os , sys <EOL> try : <EOL> import nbt <EOL> except ImportError : <EOL> extrasearchpath = os . path . realpath ( os . path . join ( __file__ , os . pardir , os . pardir ) ) <EOL> if not os . path . exists ( os . path . join ( extrasearchpath , '<STR_LIT>' ) ) : <EOL> raise <EOL> sys . path . append ( extrasearchpath ) <EOL> from nbt . world import WorldFolder <EOL> class Position ( object ) : <EOL> def __init__ ( self , x , y , z ) : <EOL> self . x = x <EOL> self . y = y <EOL> self . z = z <EOL> class Chest ( object ) : <EOL> def __init__ ( self , type , pos , items ) : <EOL> self . type = type <EOL> self . pos = Position ( * pos ) <EOL> self . items = items <EOL> def items_from_nbt ( nbtlist ) : <EOL> items = { } <EOL> for item in nbtlist : <EOL> id = item [ '<STR_LIT:id>' ] . value <EOL> count = item [ '<STR_LIT>' ] . value <EOL> if id not in items : <EOL> items [ id ] = <NUM_LIT:0> <EOL> items [ id ] += count <EOL> return items <EOL> def chests_per_chunk ( chunk ) : <EOL> """<STR_LIT>""" <EOL> entities = [ ] <EOL> for entity in chunk [ '<STR_LIT>' ] : <EOL> if entity [ "<STR_LIT:id>" ] . value == "<STR_LIT>" and entity [ "<STR_LIT:type>" ] . value == <NUM_LIT:1> : <EOL> x , y , z = entity [ "<STR_LIT>" ] <EOL> x , y , z = x . value , y , value , z . value <EOL> items = items_from_nbt ( entity [ "<STR_LIT>" ] ) <EOL> entities . append ( Chest ( "<STR_LIT>" , ( x , y , z ) , items ) ) <EOL> for entity in chunk [ '<STR_LIT>' ] : <EOL> if entity [ "<STR_LIT:id>" ] . value == "<STR_LIT>" : <EOL> x , y , z = entity [ "<STR_LIT:x>" ] . value , entity [ "<STR_LIT:y>" ] . value , entity [ "<STR_LIT:z>" ] . value <EOL> items = items_from_nbt ( entity [ "<STR_LIT>" ] ) <EOL> entities . append ( Chest ( "<STR_LIT>" , ( x , y , z ) , items ) ) <EOL> return entities <EOL> def print_results ( chests ) : <EOL> locale . setlocale ( locale . LC_ALL , '<STR_LIT>' ) <EOL> for chest in chests : <EOL> itemcount = sum ( chest . items . values ( ) ) <EOL> print ( "<STR_LIT>" % ( chest . type , locale . format ( "<STR_LIT>" , chest . pos . x , grouping = True ) , locale . format ( "<STR_LIT>" , chest . pos . y , grouping = True ) , locale . format ( "<STR_LIT>" , chest . pos . z , grouping = True ) , itemcount ) ) <EOL> for blockid , count in chest . items . items ( ) : <EOL> print ( "<STR_LIT>" % ( count , blockid ) ) <EOL> def main ( world_folder ) : <EOL> world = WorldFolder ( world_folder ) <EOL> try : <EOL> for chunk in world . iter_nbt ( ) : <EOL> print_results ( chests_per_chunk ( chunk [ "<STR_LIT>" ] ) ) <EOL> except KeyboardInterrupt : <EOL> return <NUM_LIT> <EOL> return <NUM_LIT:0> <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if ( len ( sys . argv ) == <NUM_LIT:1> ) : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:64> ) <EOL> world_folder = sys . argv [ <NUM_LIT:1> ] <EOL> world_folder = os . path . normpath ( world_folder ) <EOL> if ( not os . path . exists ( world_folder ) ) : <EOL> print ( "<STR_LIT>" + world_folder ) <EOL> sys . exit ( <NUM_LIT> ) <EOL> sys . exit ( main ( world_folder ) ) </s>
