<s> '''<STR_LIT>''' <EOL> import atexit <EOL> from contextlib import closing <EOL> import os <EOL> import shutil <EOL> import zipfile <EOL> from logging import getLogger <EOL> import blockrotation <EOL> from box import BoundingBox <EOL> import infiniteworld <EOL> from level import MCLevel , EntityLevel <EOL> from materials import alphaMaterials , MCMaterials , namedMaterials <EOL> from mclevelbase import exhaust <EOL> import nbt <EOL> from numpy import array , swapaxes , uint8 , zeros , resize <EOL> log = getLogger ( __name__ ) <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> class MCSchematic ( EntityLevel ) : <EOL> materials = alphaMaterials <EOL> def __init__ ( self , shape = None , root_tag = None , filename = None , mats = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if filename : <EOL> self . filename = filename <EOL> if None is root_tag and os . path . exists ( filename ) : <EOL> root_tag = nbt . load ( filename ) <EOL> else : <EOL> self . filename = None <EOL> if mats in namedMaterials : <EOL> self . materials = namedMaterials [ mats ] <EOL> else : <EOL> assert ( isinstance ( mats , MCMaterials ) ) <EOL> self . materials = mats <EOL> if root_tag : <EOL> self . root_tag = root_tag <EOL> if "<STR_LIT>" in root_tag : <EOL> self . materials = namedMaterials [ self . Materials ] <EOL> else : <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_String ( self . materials . name ) <EOL> w = self . root_tag [ "<STR_LIT>" ] . value <EOL> l = self . root_tag [ "<STR_LIT>" ] . value <EOL> h = self . root_tag [ "<STR_LIT>" ] . value <EOL> self . _Blocks = self . root_tag [ "<STR_LIT>" ] . value . astype ( '<STR_LIT>' ) . reshape ( h , l , w ) <EOL> del self . root_tag [ "<STR_LIT>" ] <EOL> if "<STR_LIT>" in self . root_tag : <EOL> size = ( h * l * w ) <EOL> add = zeros ( size + ( size & <NUM_LIT:1> ) , '<STR_LIT>' ) <EOL> add [ : : <NUM_LIT:2> ] = self . root_tag [ "<STR_LIT>" ] . value <EOL> add [ <NUM_LIT:1> : : <NUM_LIT:2> ] = add [ : : <NUM_LIT:2> ] & <NUM_LIT> <EOL> add [ : : <NUM_LIT:2> ] >>= <NUM_LIT:4> <EOL> add <<= <NUM_LIT:8> <EOL> self . _Blocks |= add [ : size ] . reshape ( h , l , w ) <EOL> del self . root_tag [ "<STR_LIT>" ] <EOL> self . root_tag [ "<STR_LIT>" ] . value = self . root_tag [ "<STR_LIT>" ] . value . reshape ( h , l , w ) <EOL> if "<STR_LIT>" in self . root_tag : <EOL> self . root_tag [ "<STR_LIT>" ] . value . shape = ( l , w ) <EOL> else : <EOL> assert shape is not None <EOL> root_tag = nbt . TAG_Compound ( name = "<STR_LIT>" ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Short ( shape [ <NUM_LIT:1> ] ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Short ( shape [ <NUM_LIT:2> ] ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Short ( shape [ <NUM_LIT:0> ] ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_List ( ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_List ( ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_String ( self . materials . name ) <EOL> self . _Blocks = zeros ( ( shape [ <NUM_LIT:1> ] , shape [ <NUM_LIT:2> ] , shape [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Byte_Array ( zeros ( ( shape [ <NUM_LIT:1> ] , shape [ <NUM_LIT:2> ] , shape [ <NUM_LIT:0> ] ) , uint8 ) ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Byte_Array ( zeros ( ( shape [ <NUM_LIT:2> ] , shape [ <NUM_LIT:0> ] ) , uint8 ) ) <EOL> self . root_tag = root_tag <EOL> self . root_tag [ "<STR_LIT>" ] . value &= <NUM_LIT> <EOL> def saveToFile ( self , filename = None ) : <EOL> """<STR_LIT>""" <EOL> if filename is None : <EOL> filename = self . filename <EOL> if filename is None : <EOL> raise IOError , u"<STR_LIT>" <EOL> self . Materials = self . materials . name <EOL> self . root_tag [ "<STR_LIT>" ] = nbt . TAG_Byte_Array ( self . _Blocks . astype ( '<STR_LIT>' ) ) <EOL> add = self . _Blocks >> <NUM_LIT:8> <EOL> if add . any ( ) : <EOL> packed_add = zeros ( add . size + ( add . size & <NUM_LIT:1> ) , '<STR_LIT>' ) <EOL> packed_add [ : add . size ] = add . ravel ( ) <EOL> packed_add [ : : <NUM_LIT:2> ] <<= <NUM_LIT:4> <EOL> packed_add [ : : <NUM_LIT:2> ] |= packed_add [ <NUM_LIT:1> : : <NUM_LIT:2> ] <EOL> packed_add = packed_add [ <NUM_LIT:0> : : <NUM_LIT:2> ] <EOL> self . root_tag [ "<STR_LIT>" ] = nbt . TAG_Byte_Array ( packed_add ) <EOL> with open ( filename , '<STR_LIT:wb>' ) as chunkfh : <EOL> self . root_tag . save ( chunkfh ) <EOL> del self . root_tag [ "<STR_LIT>" ] <EOL> self . root_tag . pop ( "<STR_LIT>" , None ) <EOL> def __str__ ( self ) : <EOL> return u"<STR_LIT>" . format ( self . size , self . filename or u"<STR_LIT>" , self . Materials ) <EOL> @ property <EOL> def Length ( self ) : <EOL> return self . Blocks . shape [ <NUM_LIT:1> ] <EOL> @ property <EOL> def Width ( self ) : <EOL> return self . Blocks . shape [ <NUM_LIT:0> ] <EOL> @ property <EOL> def Height ( self ) : <EOL> return self . Blocks . shape [ <NUM_LIT:2> ] <EOL> @ property <EOL> def Blocks ( self ) : <EOL> return swapaxes ( self . _Blocks , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> @ property <EOL> def Data ( self ) : <EOL> return swapaxes ( self . root_tag [ "<STR_LIT>" ] . value , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> @ property <EOL> def Entities ( self ) : <EOL> return self . root_tag [ "<STR_LIT>" ] <EOL> @ property <EOL> def TileEntities ( self ) : <EOL> return self . root_tag [ "<STR_LIT>" ] <EOL> @ property <EOL> def Materials ( self ) : <EOL> return self . root_tag [ "<STR_LIT>" ] . value <EOL> @ Materials . setter <EOL> def Materials ( self , val ) : <EOL> if "<STR_LIT>" not in self . root_tag : <EOL> self . root_tag [ "<STR_LIT>" ] = nbt . TAG_String ( ) <EOL> self . root_tag [ "<STR_LIT>" ] . value = val <EOL> @ property <EOL> def Biomes ( self ) : <EOL> return swapaxes ( self . root_tag [ "<STR_LIT>" ] . value , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> @ classmethod <EOL> def _isTagLevel ( cls , root_tag ) : <EOL> return "<STR_LIT>" == root_tag . name <EOL> def _update_shape ( self ) : <EOL> root_tag = self . root_tag <EOL> shape = self . Blocks . shape <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Short ( shape [ <NUM_LIT:2> ] ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Short ( shape [ <NUM_LIT:1> ] ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Short ( shape [ <NUM_LIT:0> ] ) <EOL> def rotateLeft ( self ) : <EOL> self . _fakeEntities = None <EOL> self . _Blocks = swapaxes ( self . _Blocks , <NUM_LIT:1> , <NUM_LIT:2> ) [ : , : : - <NUM_LIT:1> , : ] <EOL> if "<STR_LIT>" in self . root_tag : <EOL> self . root_tag [ "<STR_LIT>" ] . value = swapaxes ( self . root_tag [ "<STR_LIT>" ] . value , <NUM_LIT:0> , <NUM_LIT:1> ) [ : : - <NUM_LIT:1> , : ] <EOL> self . root_tag [ "<STR_LIT>" ] . value = swapaxes ( self . root_tag [ "<STR_LIT>" ] . value , <NUM_LIT:1> , <NUM_LIT:2> ) [ : , : : - <NUM_LIT:1> , : ] <EOL> self . _update_shape ( ) <EOL> blockrotation . RotateLeft ( self . Blocks , self . Data ) <EOL> log . info ( u"<STR_LIT>" ) <EOL> for entity in self . Entities : <EOL> for p in "<STR_LIT>" , "<STR_LIT>" : <EOL> if p == "<STR_LIT>" : <EOL> zBase = self . Length <EOL> else : <EOL> zBase = <NUM_LIT:0.0> <EOL> newX = entity [ p ] [ <NUM_LIT:2> ] . value <EOL> newZ = zBase - entity [ p ] [ <NUM_LIT:0> ] . value <EOL> entity [ p ] [ <NUM_LIT:0> ] . value = newX <EOL> entity [ p ] [ <NUM_LIT:2> ] . value = newZ <EOL> entity [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . value -= <NUM_LIT> <EOL> if entity [ "<STR_LIT:id>" ] . value in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> x , z = entity [ "<STR_LIT>" ] . value , entity [ "<STR_LIT>" ] . value <EOL> newx = z <EOL> newz = self . Length - x - <NUM_LIT:1> <EOL> entity [ "<STR_LIT>" ] . value , entity [ "<STR_LIT>" ] . value = newx , newz <EOL> entity [ "<STR_LIT>" ] . value = ( entity [ "<STR_LIT>" ] . value + <NUM_LIT:1> ) % <NUM_LIT:4> <EOL> for tileEntity in self . TileEntities : <EOL> if not '<STR_LIT:x>' in tileEntity : <EOL> continue <EOL> newX = tileEntity [ "<STR_LIT:z>" ] . value <EOL> newZ = self . Length - tileEntity [ "<STR_LIT:x>" ] . value - <NUM_LIT:1> <EOL> tileEntity [ "<STR_LIT:x>" ] . value = newX <EOL> tileEntity [ "<STR_LIT:z>" ] . value = newZ <EOL> def roll ( self ) : <EOL> "<STR_LIT>" <EOL> self . root_tag . pop ( '<STR_LIT>' , None ) <EOL> self . _fakeEntities = None <EOL> self . _Blocks = swapaxes ( self . _Blocks , <NUM_LIT:2> , <NUM_LIT:0> ) [ : , : , : : - <NUM_LIT:1> ] <EOL> self . root_tag [ "<STR_LIT>" ] . value = swapaxes ( self . root_tag [ "<STR_LIT>" ] . value , <NUM_LIT:2> , <NUM_LIT:0> ) [ : , : , : : - <NUM_LIT:1> ] <EOL> self . _update_shape ( ) <EOL> def flipVertical ( self ) : <EOL> "<STR_LIT>" <EOL> self . _fakeEntities = None <EOL> blockrotation . FlipVertical ( self . Blocks , self . Data ) <EOL> self . _Blocks = self . _Blocks [ : : - <NUM_LIT:1> , : , : ] <EOL> self . root_tag [ "<STR_LIT>" ] . value = self . root_tag [ "<STR_LIT>" ] . value [ : : - <NUM_LIT:1> , : , : ] <EOL> def flipNorthSouth ( self ) : <EOL> if "<STR_LIT>" in self . root_tag : <EOL> self . root_tag [ "<STR_LIT>" ] . value = self . root_tag [ "<STR_LIT>" ] . value [ : : - <NUM_LIT:1> , : ] <EOL> self . _fakeEntities = None <EOL> blockrotation . FlipNorthSouth ( self . Blocks , self . Data ) <EOL> self . _Blocks = self . _Blocks [ : , : , : : - <NUM_LIT:1> ] <EOL> self . root_tag [ "<STR_LIT>" ] . value = self . root_tag [ "<STR_LIT>" ] . value [ : , : , : : - <NUM_LIT:1> ] <EOL> northSouthPaintingMap = [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> log . info ( u"<STR_LIT>" ) <EOL> for entity in self . Entities : <EOL> entity [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . value = self . Width - entity [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . value <EOL> entity [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . value = - entity [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . value <EOL> entity [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . value -= <NUM_LIT> <EOL> if entity [ "<STR_LIT:id>" ] . value in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> entity [ "<STR_LIT>" ] . value = self . Width - entity [ "<STR_LIT>" ] . value <EOL> entity [ "<STR_LIT>" ] . value = northSouthPaintingMap [ entity [ "<STR_LIT>" ] . value ] <EOL> for tileEntity in self . TileEntities : <EOL> if not '<STR_LIT:x>' in tileEntity : <EOL> continue <EOL> tileEntity [ "<STR_LIT:x>" ] . value = self . Width - tileEntity [ "<STR_LIT:x>" ] . value - <NUM_LIT:1> <EOL> def flipEastWest ( self ) : <EOL> if "<STR_LIT>" in self . root_tag : <EOL> self . root_tag [ "<STR_LIT>" ] . value = self . root_tag [ "<STR_LIT>" ] . value [ : , : : - <NUM_LIT:1> ] <EOL> self . _fakeEntities = None <EOL> blockrotation . FlipEastWest ( self . Blocks , self . Data ) <EOL> self . _Blocks = self . _Blocks [ : , : : - <NUM_LIT:1> , : ] <EOL> self . root_tag [ "<STR_LIT>" ] . value = self . root_tag [ "<STR_LIT>" ] . value [ : , : : - <NUM_LIT:1> , : ] <EOL> eastWestPaintingMap = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:3> ] <EOL> log . info ( u"<STR_LIT>" ) <EOL> for entity in self . Entities : <EOL> entity [ "<STR_LIT>" ] [ <NUM_LIT:2> ] . value = self . Length - entity [ "<STR_LIT>" ] [ <NUM_LIT:2> ] . value <EOL> entity [ "<STR_LIT>" ] [ <NUM_LIT:2> ] . value = - entity [ "<STR_LIT>" ] [ <NUM_LIT:2> ] . value <EOL> entity [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . value -= <NUM_LIT> <EOL> if entity [ "<STR_LIT:id>" ] . value in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> entity [ "<STR_LIT>" ] . value = self . Length - entity [ "<STR_LIT>" ] . value <EOL> entity [ "<STR_LIT>" ] . value = eastWestPaintingMap [ entity [ "<STR_LIT>" ] . value ] <EOL> for tileEntity in self . TileEntities : <EOL> tileEntity [ "<STR_LIT:z>" ] . value = self . Length - tileEntity [ "<STR_LIT:z>" ] . value - <NUM_LIT:1> <EOL> def setBlockDataAt ( self , x , y , z , newdata ) : <EOL> if x < <NUM_LIT:0> or y < <NUM_LIT:0> or z < <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> if x >= self . Width or y >= self . Height or z >= self . Length : <EOL> return <NUM_LIT:0> <EOL> self . Data [ x , z , y ] = ( newdata & <NUM_LIT> ) <EOL> def blockDataAt ( self , x , y , z ) : <EOL> if x < <NUM_LIT:0> or y < <NUM_LIT:0> or z < <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> if x >= self . Width or y >= self . Height or z >= self . Length : <EOL> return <NUM_LIT:0> <EOL> return self . Data [ x , z , y ] <EOL> @ classmethod <EOL> def chestWithItemID ( cls , itemID , count = <NUM_LIT:64> , damage = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> root_tag = nbt . TAG_Compound ( ) <EOL> invTag = nbt . TAG_List ( ) <EOL> root_tag [ "<STR_LIT>" ] = invTag <EOL> for slot in range ( <NUM_LIT:9> , <NUM_LIT> ) : <EOL> itemTag = nbt . TAG_Compound ( ) <EOL> itemTag [ "<STR_LIT>" ] = nbt . TAG_Byte ( slot ) <EOL> itemTag [ "<STR_LIT>" ] = nbt . TAG_Byte ( count ) <EOL> itemTag [ "<STR_LIT:id>" ] = nbt . TAG_Short ( itemID ) <EOL> itemTag [ "<STR_LIT>" ] = nbt . TAG_Short ( damage ) <EOL> invTag . append ( itemTag ) <EOL> chest = INVEditChest ( root_tag , "<STR_LIT>" ) <EOL> return chest <EOL> def getChunk ( self , cx , cz ) : <EOL> chunk = super ( MCSchematic , self ) . getChunk ( cx , cz ) <EOL> if "<STR_LIT>" in self . root_tag : <EOL> x = cx << <NUM_LIT:4> <EOL> z = cz << <NUM_LIT:4> <EOL> chunk . Biomes = self . Biomes [ x : x + <NUM_LIT:16> , z : z + <NUM_LIT:16> ] <EOL> return chunk <EOL> class INVEditChest ( MCSchematic ) : <EOL> Width = <NUM_LIT:1> <EOL> Height = <NUM_LIT:1> <EOL> Length = <NUM_LIT:1> <EOL> Blocks = array ( [ [ [ alphaMaterials . Chest . ID ] ] ] , '<STR_LIT>' ) <EOL> Data = array ( [ [ [ <NUM_LIT:0> ] ] ] , '<STR_LIT>' ) <EOL> Entities = nbt . TAG_List ( ) <EOL> Materials = alphaMaterials <EOL> @ classmethod <EOL> def _isTagLevel ( cls , root_tag ) : <EOL> return "<STR_LIT>" in root_tag <EOL> def __init__ ( self , root_tag , filename ) : <EOL> if filename : <EOL> self . filename = filename <EOL> if None is root_tag : <EOL> try : <EOL> root_tag = nbt . load ( filename ) <EOL> except IOError , e : <EOL> log . info ( u"<STR_LIT>" . format ( e ) ) <EOL> raise <EOL> else : <EOL> assert root_tag , "<STR_LIT>" <EOL> self . filename = None <EOL> for item in list ( root_tag [ "<STR_LIT>" ] ) : <EOL> slot = item [ "<STR_LIT>" ] . value <EOL> if slot < <NUM_LIT:9> or slot >= <NUM_LIT> : <EOL> root_tag [ "<STR_LIT>" ] . remove ( item ) <EOL> else : <EOL> item [ "<STR_LIT>" ] . value -= <NUM_LIT:9> <EOL> self . root_tag = root_tag <EOL> @ property <EOL> def TileEntities ( self ) : <EOL> chestTag = nbt . TAG_Compound ( ) <EOL> chestTag [ "<STR_LIT:id>" ] = nbt . TAG_String ( "<STR_LIT>" ) <EOL> chestTag [ "<STR_LIT>" ] = nbt . TAG_List ( self . root_tag [ "<STR_LIT>" ] ) <EOL> chestTag [ "<STR_LIT:x>" ] = nbt . TAG_Int ( <NUM_LIT:0> ) <EOL> chestTag [ "<STR_LIT:y>" ] = nbt . TAG_Int ( <NUM_LIT:0> ) <EOL> chestTag [ "<STR_LIT:z>" ] = nbt . TAG_Int ( <NUM_LIT:0> ) <EOL> return nbt . TAG_List ( [ chestTag ] , name = "<STR_LIT>" ) <EOL> class ZipSchematic ( infiniteworld . MCInfdevOldLevel ) : <EOL> def __init__ ( self , filename , create = False ) : <EOL> self . zipfilename = filename <EOL> tempdir = tempfile . mktemp ( "<STR_LIT>" ) <EOL> if create is False : <EOL> zf = zipfile . ZipFile ( filename ) <EOL> zf . extractall ( tempdir ) <EOL> zf . close ( ) <EOL> super ( ZipSchematic , self ) . __init__ ( tempdir , create ) <EOL> atexit . register ( shutil . rmtree , self . worldFolder . filename , True ) <EOL> try : <EOL> schematicDat = nbt . load ( self . worldFolder . getFilePath ( "<STR_LIT>" ) ) <EOL> self . Width = schematicDat [ '<STR_LIT>' ] . value <EOL> self . Height = schematicDat [ '<STR_LIT>' ] . value <EOL> self . Length = schematicDat [ '<STR_LIT>' ] . value <EOL> if "<STR_LIT>" in schematicDat : <EOL> self . materials = namedMaterials [ schematicDat [ "<STR_LIT>" ] . value ] <EOL> except Exception , e : <EOL> print "<STR_LIT>" . format ( e ) <EOL> self . Width = <NUM_LIT:0> <EOL> self . Length = <NUM_LIT:0> <EOL> def __del__ ( self ) : <EOL> shutil . rmtree ( self . worldFolder . filename , True ) <EOL> def saveInPlace ( self ) : <EOL> self . saveToFile ( self . zipfilename ) <EOL> def saveToFile ( self , filename ) : <EOL> super ( ZipSchematic , self ) . saveInPlace ( ) <EOL> schematicDat = nbt . TAG_Compound ( ) <EOL> schematicDat . name = "<STR_LIT>" <EOL> schematicDat [ "<STR_LIT>" ] = nbt . TAG_Int ( self . size [ <NUM_LIT:0> ] ) <EOL> schematicDat [ "<STR_LIT>" ] = nbt . TAG_Int ( self . size [ <NUM_LIT:1> ] ) <EOL> schematicDat [ "<STR_LIT>" ] = nbt . TAG_Int ( self . size [ <NUM_LIT:2> ] ) <EOL> schematicDat [ "<STR_LIT>" ] = nbt . TAG_String ( self . materials . name ) <EOL> schematicDat . save ( self . worldFolder . getFilePath ( "<STR_LIT>" ) ) <EOL> basedir = self . worldFolder . filename <EOL> assert os . path . isdir ( basedir ) <EOL> with closing ( zipfile . ZipFile ( filename , "<STR_LIT:w>" , zipfile . ZIP_STORED ) ) as z : <EOL> for root , dirs , files in os . walk ( basedir ) : <EOL> for fn in files : <EOL> absfn = os . path . join ( root , fn ) <EOL> zfn = absfn [ len ( basedir ) + len ( os . sep ) : ] <EOL> z . write ( absfn , zfn ) <EOL> def getWorldBounds ( self ) : <EOL> return BoundingBox ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , ( self . Width , self . Height , self . Length ) ) <EOL> @ classmethod <EOL> def _isLevel ( cls , filename ) : <EOL> return zipfile . is_zipfile ( filename ) <EOL> def adjustExtractionParameters ( self , box ) : <EOL> x , y , z = box . origin <EOL> w , h , l = box . size <EOL> destX = destY = destZ = <NUM_LIT:0> <EOL> if y < <NUM_LIT:0> : <EOL> destY -= y <EOL> h += y <EOL> y = <NUM_LIT:0> <EOL> if y >= self . Height : <EOL> return <EOL> if y + h >= self . Height : <EOL> h -= y + h - self . Height <EOL> y = self . Height - h <EOL> if h <= <NUM_LIT:0> : <EOL> return <EOL> if self . Width : <EOL> if x < <NUM_LIT:0> : <EOL> w += x <EOL> destX -= x <EOL> x = <NUM_LIT:0> <EOL> if x >= self . Width : <EOL> return <EOL> if x + w >= self . Width : <EOL> w = self . Width - x <EOL> if w <= <NUM_LIT:0> : <EOL> return <EOL> if z < <NUM_LIT:0> : <EOL> l += z <EOL> destZ -= z <EOL> z = <NUM_LIT:0> <EOL> if z >= self . Length : <EOL> return <EOL> if z + l >= self . Length : <EOL> l = self . Length - z <EOL> if l <= <NUM_LIT:0> : <EOL> return <EOL> box = BoundingBox ( ( x , y , z ) , ( w , h , l ) ) <EOL> return box , ( destX , destY , destZ ) <EOL> def extractSchematicFrom ( sourceLevel , box , entities = True ) : <EOL> return exhaust ( extractSchematicFromIter ( sourceLevel , box , entities ) ) <EOL> def extractSchematicFromIter ( sourceLevel , box , entities = True ) : <EOL> p = sourceLevel . adjustExtractionParameters ( box ) <EOL> if p is None : <EOL> yield None <EOL> return <EOL> newbox , destPoint = p <EOL> tempSchematic = MCSchematic ( shape = box . size , mats = sourceLevel . materials ) <EOL> for i in tempSchematic . copyBlocksFromIter ( sourceLevel , newbox , destPoint , entities = entities , biomes = True ) : <EOL> yield i <EOL> yield tempSchematic <EOL> MCLevel . extractSchematic = extractSchematicFrom <EOL> MCLevel . extractSchematicIter = extractSchematicFromIter <EOL> MCLevel . adjustExtractionParameters = adjustExtractionParameters <EOL> import tempfile <EOL> def extractZipSchematicFrom ( sourceLevel , box , zipfilename = None , entities = True ) : <EOL> return exhaust ( extractZipSchematicFromIter ( sourceLevel , box , zipfilename , entities ) ) <EOL> def extractZipSchematicFromIter ( sourceLevel , box , zipfilename = None , entities = True ) : <EOL> if zipfilename is None : <EOL> zipfilename = tempfile . mktemp ( "<STR_LIT>" ) <EOL> atexit . register ( shutil . rmtree , zipfilename , True ) <EOL> p = sourceLevel . adjustExtractionParameters ( box ) <EOL> if p is None : <EOL> return <EOL> sourceBox , destPoint = p <EOL> destPoint = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> tempSchematic = ZipSchematic ( zipfilename , create = True ) <EOL> tempSchematic . materials = sourceLevel . materials <EOL> for i in tempSchematic . copyBlocksFromIter ( sourceLevel , sourceBox , destPoint , entities = entities , create = True , biomes = True ) : <EOL> yield i <EOL> tempSchematic . Width , tempSchematic . Height , tempSchematic . Length = sourceBox . size <EOL> tempSchematic . saveInPlace ( ) <EOL> yield tempSchematic <EOL> MCLevel . extractZipSchematic = extractZipSchematicFrom <EOL> MCLevel . extractZipSchematicIter = extractZipSchematicFromIter <EOL> def extractAnySchematic ( level , box ) : <EOL> return exhaust ( level . extractAnySchematicIter ( box ) ) <EOL> def extractAnySchematicIter ( level , box ) : <EOL> if box . chunkCount < infiniteworld . MCInfdevOldLevel . loadedChunkLimit : <EOL> for i in level . extractSchematicIter ( box ) : <EOL> yield i <EOL> else : <EOL> for i in level . extractZipSchematicIter ( box ) : <EOL> yield i <EOL> MCLevel . extractAnySchematic = extractAnySchematic <EOL> MCLevel . extractAnySchematicIter = extractAnySchematicIter </s>
