<s> """<STR_LIT>""" <EOL> import os , sys <EOL> import itertools <EOL> try : <EOL> zip_longest = itertools . zip_longest <EOL> except AttributeError : <EOL> zip_longest = itertools . izip_longest <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> import nbt <EOL> def array_4bit_to_byte ( array ) : <EOL> """<STR_LIT>""" <EOL> def iterarray ( array ) : <EOL> for b in array : <EOL> yield ( b & <NUM_LIT:15> ) <EOL> yield ( ( b >> <NUM_LIT:4> ) & <NUM_LIT:15> ) <EOL> return bytearray ( iterarray ( array ) ) <EOL> def array_byte_to_4bit ( array ) : <EOL> """<STR_LIT>""" <EOL> def iterarray ( array ) : <EOL> arrayiter = iter ( array ) <EOL> for b1 in arrayiter : <EOL> b2 = next ( arrayiter , <NUM_LIT:0> ) <EOL> yield ( ( ( b2 & <NUM_LIT:15> ) << <NUM_LIT:4> ) + ( b1 & <NUM_LIT:15> ) ) <EOL> return bytearray ( iterarray ( array ) ) <EOL> def grouper ( iterable , n , fillvalue = None ) : <EOL> "<STR_LIT>" <EOL> args = [ iter ( iterable ) ] * n <EOL> return zip_longest ( * args , fillvalue = fillvalue ) <EOL> def print_chunklayer ( blocks , data , add , yoffset ) : <EOL> blocks = list ( blocks [ yoffset * <NUM_LIT> : ( yoffset + <NUM_LIT:1> ) * <NUM_LIT> ] ) <EOL> data = array_4bit_to_byte ( data [ yoffset * <NUM_LIT> : ( yoffset + <NUM_LIT:1> ) * <NUM_LIT> ] ) <EOL> if add is not None : <EOL> add = array_4bit_to_byte ( add [ yoffset * <NUM_LIT> : ( yoffset + <NUM_LIT:1> ) * <NUM_LIT> ] ) <EOL> for i , v in enumerate ( add ) : <EOL> blocks [ i ] += <NUM_LIT> * v <EOL> assert len ( blocks ) == <NUM_LIT> <EOL> assert len ( data ) == <NUM_LIT> <EOL> for row in grouper ( zip ( blocks , data ) , <NUM_LIT:16> ) : <EOL> print ( "<STR_LIT:U+0020>" . join ( ( "<STR_LIT>" % block ) for block in row ) ) <EOL> def get_section ( world , chunkx , chunky , chunkz ) : <EOL> """<STR_LIT>""" <EOL> chunk = world . get_nbt ( chunkx , chunkz ) <EOL> for section in chunk [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> if section [ '<STR_LIT:Y>' ] . value == chunky : <EOL> return section <EOL> raise nbt . region . InconceivedChunk ( "<STR_LIT>" ) <EOL> def main ( world_folder , chunkx , chunkz , height ) : <EOL> world = nbt . world . WorldFolder ( world_folder ) <EOL> if not isinstance ( world , nbt . world . AnvilWorldFolder ) : <EOL> print ( "<STR_LIT>" % ( world_folder ) ) <EOL> return <NUM_LIT> <EOL> chunky , yoffset = divmod ( height , <NUM_LIT:16> ) <EOL> try : <EOL> section = get_section ( world , chunkx , chunky , chunkz ) <EOL> try : <EOL> blocks = section [ '<STR_LIT>' ] . value <EOL> data = section [ '<STR_LIT>' ] . value <EOL> except ( KeyError , AttributeError ) : <EOL> blocks = bytearray ( <NUM_LIT> ) <EOL> data = bytearray ( <NUM_LIT> ) <EOL> try : <EOL> add = section [ '<STR_LIT>' ] . value <EOL> except ( KeyError , AttributeError ) : <EOL> add = None <EOL> except nbt . region . InconceivedChunk : <EOL> print ( "<STR_LIT>" ) <EOL> blocks = bytearray ( <NUM_LIT> ) <EOL> data = bytearray ( <NUM_LIT> ) <EOL> add = None <EOL> print_chunklayer ( blocks , data , add , yoffset ) <EOL> return <NUM_LIT:0> <EOL> def usage ( message = None , appname = None ) : <EOL> if appname == None : <EOL> appname = os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) <EOL> print ( "<STR_LIT>" % appname ) <EOL> if message : <EOL> print ( "<STR_LIT>" % ( appname , message ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if ( len ( sys . argv ) != <NUM_LIT:5> ) : <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:64> ) <EOL> world_folder = sys . argv [ <NUM_LIT:1> ] <EOL> try : <EOL> chunkx = int ( sys . argv [ <NUM_LIT:2> ] ) <EOL> except ValueError : <EOL> usage ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:64> ) <EOL> try : <EOL> chunkz = int ( sys . argv [ <NUM_LIT:3> ] ) <EOL> except ValueError : <EOL> usage ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:64> ) <EOL> try : <EOL> height = int ( sys . argv [ <NUM_LIT:4> ] ) <EOL> except ValueError : <EOL> usage ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:64> ) <EOL> world_folder = os . path . normpath ( world_folder ) <EOL> if ( not os . path . exists ( world_folder ) ) : <EOL> usage ( "<STR_LIT>" + world_folder ) <EOL> sys . exit ( <NUM_LIT> ) <EOL> sys . exit ( main ( world_folder , chunkx , chunkz , height ) ) </s>
