<s> '''<STR_LIT>''' <EOL> import copy <EOL> from datetime import datetime <EOL> import itertools <EOL> from logging import getLogger <EOL> from math import floor <EOL> import os <EOL> import re <EOL> import random <EOL> import shutil <EOL> import struct <EOL> import time <EOL> import traceback <EOL> import weakref <EOL> import zlib <EOL> import sys <EOL> import blockrotation <EOL> from box import BoundingBox <EOL> from entity import Entity , TileEntity <EOL> from faces import FaceXDecreasing , FaceXIncreasing , FaceZDecreasing , FaceZIncreasing <EOL> from level import LightedChunk , EntityLevel , computeChunkHeightMap , MCLevel , ChunkBase <EOL> from materials import alphaMaterials <EOL> from mclevelbase import ChunkMalformed , ChunkNotPresent , exhaust , PlayerNotFound <EOL> import nbt <EOL> from numpy import array , clip , maximum , zeros <EOL> from regionfile import MCRegionFile <EOL> log = getLogger ( __name__ ) <EOL> DIM_NETHER = - <NUM_LIT:1> <EOL> DIM_END = <NUM_LIT:1> <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> _zeros = { } <EOL> class SessionLockLost ( IOError ) : <EOL> pass <EOL> def ZeroChunk ( height = <NUM_LIT> ) : <EOL> z = _zeros . get ( height ) <EOL> if z is None : <EOL> z = _zeros [ height ] = _ZeroChunk ( height ) <EOL> return z <EOL> class _ZeroChunk ( ChunkBase ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , height = <NUM_LIT> ) : <EOL> zeroChunk = zeros ( ( <NUM_LIT:16> , <NUM_LIT:16> , height ) , '<STR_LIT>' ) <EOL> whiteLight = zeroChunk + <NUM_LIT:15> <EOL> self . Blocks = zeroChunk <EOL> self . BlockLight = whiteLight <EOL> self . SkyLight = whiteLight <EOL> self . Data = zeroChunk <EOL> def unpackNibbleArray ( dataArray ) : <EOL> s = dataArray . shape <EOL> unpackedData = zeros ( ( s [ <NUM_LIT:0> ] , s [ <NUM_LIT:1> ] , s [ <NUM_LIT:2> ] * <NUM_LIT:2> ) , dtype = '<STR_LIT>' ) <EOL> unpackedData [ : , : , : : <NUM_LIT:2> ] = dataArray <EOL> unpackedData [ : , : , : : <NUM_LIT:2> ] &= <NUM_LIT> <EOL> unpackedData [ : , : , <NUM_LIT:1> : : <NUM_LIT:2> ] = dataArray <EOL> unpackedData [ : , : , <NUM_LIT:1> : : <NUM_LIT:2> ] >>= <NUM_LIT:4> <EOL> return unpackedData <EOL> def packNibbleArray ( unpackedData ) : <EOL> packedData = array ( unpackedData . reshape ( <NUM_LIT:16> , <NUM_LIT:16> , unpackedData . shape [ <NUM_LIT:2> ] / <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> packedData [ ... , <NUM_LIT:1> ] <<= <NUM_LIT:4> <EOL> packedData [ ... , <NUM_LIT:1> ] |= packedData [ ... , <NUM_LIT:0> ] <EOL> return array ( packedData [ : , : , : , <NUM_LIT:1> ] ) <EOL> def sanitizeBlocks ( chunk ) : <EOL> grass = chunk . Blocks == chunk . materials . Grass . ID <EOL> grass |= chunk . Blocks == chunk . materials . Dirt . ID <EOL> badgrass = grass [ : , : , <NUM_LIT:1> : ] & grass [ : , : , : - <NUM_LIT:1> ] <EOL> chunk . Blocks [ : , : , : - <NUM_LIT:1> ] [ badgrass ] = chunk . materials . Dirt . ID <EOL> if hasattr ( chunk . materials , "<STR_LIT>" ) : <EOL> snowlayer = chunk . Blocks == chunk . materials . SnowLayer . ID <EOL> badsnow = snowlayer [ : , : , <NUM_LIT:1> : ] & snowlayer [ : , : , : - <NUM_LIT:1> ] <EOL> chunk . Blocks [ : , : , <NUM_LIT:1> : ] [ badsnow ] = chunk . materials . Air . ID <EOL> class AnvilChunkData ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , world , chunkPosition , root_tag = None , create = False ) : <EOL> self . chunkPosition = chunkPosition <EOL> self . world = world <EOL> self . root_tag = root_tag <EOL> self . dirty = False <EOL> self . Blocks = zeros ( ( <NUM_LIT:16> , <NUM_LIT:16> , world . Height ) , '<STR_LIT>' ) <EOL> self . Data = zeros ( ( <NUM_LIT:16> , <NUM_LIT:16> , world . Height ) , '<STR_LIT>' ) <EOL> self . BlockLight = zeros ( ( <NUM_LIT:16> , <NUM_LIT:16> , world . Height ) , '<STR_LIT>' ) <EOL> self . SkyLight = zeros ( ( <NUM_LIT:16> , <NUM_LIT:16> , world . Height ) , '<STR_LIT>' ) <EOL> self . SkyLight [ : ] = <NUM_LIT:15> <EOL> if create : <EOL> self . _create ( ) <EOL> else : <EOL> self . _load ( root_tag ) <EOL> levelTag = self . root_tag [ "<STR_LIT>" ] <EOL> if "<STR_LIT>" not in levelTag : <EOL> levelTag [ "<STR_LIT>" ] = nbt . TAG_Byte_Array ( zeros ( ( <NUM_LIT:16> , <NUM_LIT:16> ) , '<STR_LIT>' ) ) <EOL> levelTag [ "<STR_LIT>" ] . value [ : ] = - <NUM_LIT:1> <EOL> def _create ( self ) : <EOL> ( cx , cz ) = self . chunkPosition <EOL> chunkTag = nbt . TAG_Compound ( ) <EOL> chunkTag . name = "<STR_LIT>" <EOL> levelTag = nbt . TAG_Compound ( ) <EOL> chunkTag [ "<STR_LIT>" ] = levelTag <EOL> levelTag [ "<STR_LIT>" ] = nbt . TAG_Int_Array ( zeros ( ( <NUM_LIT:16> , <NUM_LIT:16> ) , '<STR_LIT>' ) . newbyteorder ( ) ) <EOL> levelTag [ "<STR_LIT>" ] = nbt . TAG_Byte ( <NUM_LIT:1> ) <EOL> levelTag [ "<STR_LIT>" ] = nbt . TAG_Int ( cx ) <EOL> levelTag [ "<STR_LIT>" ] = nbt . TAG_Int ( cz ) <EOL> levelTag [ "<STR_LIT>" ] = nbt . TAG_Long ( <NUM_LIT:0> ) <EOL> levelTag [ "<STR_LIT>" ] = nbt . TAG_List ( ) <EOL> levelTag [ "<STR_LIT>" ] = nbt . TAG_List ( ) <EOL> self . root_tag = chunkTag <EOL> self . dirty = True <EOL> def _load ( self , root_tag ) : <EOL> self . root_tag = root_tag <EOL> for sec in self . root_tag [ "<STR_LIT>" ] . pop ( "<STR_LIT>" , [ ] ) : <EOL> y = sec [ "<STR_LIT:Y>" ] . value * <NUM_LIT:16> <EOL> for name in "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" : <EOL> arr = getattr ( self , name ) <EOL> secarray = sec [ name ] . value <EOL> if name == "<STR_LIT>" : <EOL> secarray . shape = ( <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:16> ) <EOL> else : <EOL> secarray . shape = ( <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:8> ) <EOL> secarray = unpackNibbleArray ( secarray ) <EOL> arr [ ... , y : y + <NUM_LIT:16> ] = secarray . swapaxes ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> tag = sec . get ( "<STR_LIT>" ) <EOL> if tag is not None : <EOL> tag . value . shape = ( <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:8> ) <EOL> add = unpackNibbleArray ( tag . value ) <EOL> self . Blocks [ ... , y : y + <NUM_LIT:16> ] |= ( array ( add , '<STR_LIT>' ) << <NUM_LIT:8> ) . swapaxes ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> def savedTagData ( self ) : <EOL> """<STR_LIT>""" <EOL> log . debug ( u"<STR_LIT>" . format ( self ) ) <EOL> sanitizeBlocks ( self ) <EOL> sections = nbt . TAG_List ( ) <EOL> for y in range ( <NUM_LIT:0> , self . world . Height , <NUM_LIT:16> ) : <EOL> section = nbt . TAG_Compound ( ) <EOL> Blocks = self . Blocks [ ... , y : y + <NUM_LIT:16> ] . swapaxes ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> Data = self . Data [ ... , y : y + <NUM_LIT:16> ] . swapaxes ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> BlockLight = self . BlockLight [ ... , y : y + <NUM_LIT:16> ] . swapaxes ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> SkyLight = self . SkyLight [ ... , y : y + <NUM_LIT:16> ] . swapaxes ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> if ( not Blocks . any ( ) and <EOL> not BlockLight . any ( ) and <EOL> ( SkyLight == <NUM_LIT:15> ) . all ( ) ) : <EOL> continue <EOL> Data = packNibbleArray ( Data ) <EOL> BlockLight = packNibbleArray ( BlockLight ) <EOL> SkyLight = packNibbleArray ( SkyLight ) <EOL> add = Blocks >> <NUM_LIT:8> <EOL> if add . any ( ) : <EOL> section [ "<STR_LIT>" ] = nbt . TAG_Byte_Array ( packNibbleArray ( add ) . astype ( '<STR_LIT>' ) ) <EOL> section [ '<STR_LIT>' ] = nbt . TAG_Byte_Array ( array ( Blocks , '<STR_LIT>' ) ) <EOL> section [ '<STR_LIT>' ] = nbt . TAG_Byte_Array ( array ( Data ) ) <EOL> section [ '<STR_LIT>' ] = nbt . TAG_Byte_Array ( array ( BlockLight ) ) <EOL> section [ '<STR_LIT>' ] = nbt . TAG_Byte_Array ( array ( SkyLight ) ) <EOL> section [ "<STR_LIT:Y>" ] = nbt . TAG_Byte ( y / <NUM_LIT:16> ) <EOL> sections . append ( section ) <EOL> self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] = sections <EOL> data = self . root_tag . save ( compressed = False ) <EOL> del self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> log . debug ( u"<STR_LIT>" . format ( self ) ) <EOL> return data <EOL> @ property <EOL> def materials ( self ) : <EOL> return self . world . materials <EOL> class AnvilChunk ( LightedChunk ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , chunkData ) : <EOL> self . world = chunkData . world <EOL> self . chunkPosition = chunkData . chunkPosition <EOL> self . chunkData = chunkData <EOL> def savedTagData ( self ) : <EOL> return self . chunkData . savedTagData ( ) <EOL> def __str__ ( self ) : <EOL> return u"<STR_LIT>" . format ( self . chunkPosition , self . world . displayName , self . dirty , self . needsLighting ) <EOL> @ property <EOL> def needsLighting ( self ) : <EOL> return self . chunkPosition in self . world . chunksNeedingLighting <EOL> @ needsLighting . setter <EOL> def needsLighting ( self , value ) : <EOL> if value : <EOL> self . world . chunksNeedingLighting . add ( self . chunkPosition ) <EOL> else : <EOL> self . world . chunksNeedingLighting . discard ( self . chunkPosition ) <EOL> def generateHeightMap ( self ) : <EOL> if self . world . dimNo == DIM_NETHER : <EOL> self . HeightMap [ : ] = <NUM_LIT:0> <EOL> else : <EOL> computeChunkHeightMap ( self . materials , self . Blocks , self . HeightMap ) <EOL> def addEntity ( self , entityTag ) : <EOL> def doubleize ( name ) : <EOL> if name in entityTag : <EOL> m = entityTag [ name ] <EOL> entityTag [ name ] = nbt . TAG_List ( [ nbt . TAG_Double ( i . value ) for i in m ] ) <EOL> doubleize ( "<STR_LIT>" ) <EOL> doubleize ( "<STR_LIT>" ) <EOL> self . dirty = True <EOL> return super ( AnvilChunk , self ) . addEntity ( entityTag ) <EOL> def removeEntitiesInBox ( self , box ) : <EOL> self . dirty = True <EOL> return super ( AnvilChunk , self ) . removeEntitiesInBox ( box ) <EOL> def removeTileEntitiesInBox ( self , box ) : <EOL> self . dirty = True <EOL> return super ( AnvilChunk , self ) . removeTileEntitiesInBox ( box ) <EOL> @ property <EOL> def root_tag ( self ) : <EOL> return self . chunkData . root_tag <EOL> @ property <EOL> def dirty ( self ) : <EOL> return self . chunkData . dirty <EOL> @ dirty . setter <EOL> def dirty ( self , val ) : <EOL> self . chunkData . dirty = val <EOL> @ property <EOL> def materials ( self ) : <EOL> return self . world . materials <EOL> @ property <EOL> def Blocks ( self ) : <EOL> return self . chunkData . Blocks <EOL> @ property <EOL> def Data ( self ) : <EOL> return self . chunkData . Data <EOL> @ property <EOL> def SkyLight ( self ) : <EOL> return self . chunkData . SkyLight <EOL> @ property <EOL> def BlockLight ( self ) : <EOL> return self . chunkData . BlockLight <EOL> @ property <EOL> def Biomes ( self ) : <EOL> return self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] . value . reshape ( ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> @ property <EOL> def HeightMap ( self ) : <EOL> return self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] . value . reshape ( ( <NUM_LIT:16> , <NUM_LIT:16> ) ) <EOL> @ property <EOL> def Entities ( self ) : <EOL> return self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> @ property <EOL> def TileEntities ( self ) : <EOL> return self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> @ property <EOL> def TerrainPopulated ( self ) : <EOL> return self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] . value <EOL> @ TerrainPopulated . setter <EOL> def TerrainPopulated ( self , val ) : <EOL> """<STR_LIT>""" <EOL> self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] . value = val <EOL> self . dirty = True <EOL> base36alphabet = "<STR_LIT>" <EOL> def decbase36 ( s ) : <EOL> return int ( s , <NUM_LIT> ) <EOL> def base36 ( n ) : <EOL> global base36alphabet <EOL> n = int ( n ) <EOL> if <NUM_LIT:0> == n : <EOL> return '<STR_LIT:0>' <EOL> neg = "<STR_LIT>" <EOL> if n < <NUM_LIT:0> : <EOL> neg = "<STR_LIT:->" <EOL> n = - n <EOL> work = [ ] <EOL> while n : <EOL> n , digit = divmod ( n , <NUM_LIT> ) <EOL> work . append ( base36alphabet [ digit ] ) <EOL> return neg + '<STR_LIT>' . join ( reversed ( work ) ) <EOL> def deflate ( data ) : <EOL> return zlib . compress ( data ) <EOL> def inflate ( data ) : <EOL> return zlib . decompress ( data ) <EOL> class ChunkedLevelMixin ( MCLevel ) : <EOL> def blockLightAt ( self , x , y , z ) : <EOL> if y < <NUM_LIT:0> or y >= self . Height : <EOL> return <NUM_LIT:0> <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> ch = self . getChunk ( xc , zc ) <EOL> return ch . BlockLight [ xInChunk , zInChunk , y ] <EOL> def setBlockLightAt ( self , x , y , z , newLight ) : <EOL> if y < <NUM_LIT:0> or y >= self . Height : <EOL> return <NUM_LIT:0> <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> ch = self . getChunk ( xc , zc ) <EOL> ch . BlockLight [ xInChunk , zInChunk , y ] = newLight <EOL> ch . chunkChanged ( False ) <EOL> def blockDataAt ( self , x , y , z ) : <EOL> if y < <NUM_LIT:0> or y >= self . Height : <EOL> return <NUM_LIT:0> <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> try : <EOL> ch = self . getChunk ( xc , zc ) <EOL> except ChunkNotPresent : <EOL> return <NUM_LIT:0> <EOL> return ch . Data [ xInChunk , zInChunk , y ] <EOL> def setBlockDataAt ( self , x , y , z , newdata ) : <EOL> if y < <NUM_LIT:0> or y >= self . Height : <EOL> return <NUM_LIT:0> <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> try : <EOL> ch = self . getChunk ( xc , zc ) <EOL> except ChunkNotPresent : <EOL> return <NUM_LIT:0> <EOL> ch . Data [ xInChunk , zInChunk , y ] = newdata <EOL> ch . dirty = True <EOL> ch . needsLighting = True <EOL> def blockAt ( self , x , y , z ) : <EOL> """<STR_LIT>""" <EOL> if y < <NUM_LIT:0> or y >= self . Height : <EOL> return <NUM_LIT:0> <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> try : <EOL> ch = self . getChunk ( xc , zc ) <EOL> except ChunkNotPresent : <EOL> return <NUM_LIT:0> <EOL> return ch . Blocks [ xInChunk , zInChunk , y ] <EOL> def setBlockAt ( self , x , y , z , blockID ) : <EOL> """<STR_LIT>""" <EOL> if y < <NUM_LIT:0> or y >= self . Height : <EOL> return <NUM_LIT:0> <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> try : <EOL> ch = self . getChunk ( xc , zc ) <EOL> except ChunkNotPresent : <EOL> return <NUM_LIT:0> <EOL> ch . Blocks [ xInChunk , zInChunk , y ] = blockID <EOL> ch . dirty = True <EOL> ch . needsLighting = True <EOL> def skylightAt ( self , x , y , z ) : <EOL> if y < <NUM_LIT:0> or y >= self . Height : <EOL> return <NUM_LIT:0> <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> ch = self . getChunk ( xc , zc ) <EOL> return ch . SkyLight [ xInChunk , zInChunk , y ] <EOL> def setSkylightAt ( self , x , y , z , lightValue ) : <EOL> if y < <NUM_LIT:0> or y >= self . Height : <EOL> return <NUM_LIT:0> <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> ch = self . getChunk ( xc , zc ) <EOL> skyLight = ch . SkyLight <EOL> oldValue = skyLight [ xInChunk , zInChunk , y ] <EOL> ch . chunkChanged ( False ) <EOL> if oldValue < lightValue : <EOL> skyLight [ xInChunk , zInChunk , y ] = lightValue <EOL> return oldValue < lightValue <EOL> createChunk = NotImplemented <EOL> def generateLights ( self , dirtyChunkPositions = None ) : <EOL> return exhaust ( self . generateLightsIter ( dirtyChunkPositions ) ) <EOL> def generateLightsIter ( self , dirtyChunkPositions = None ) : <EOL> """<STR_LIT>""" <EOL> startTime = datetime . now ( ) <EOL> if dirtyChunkPositions is None : <EOL> dirtyChunkPositions = self . chunksNeedingLighting <EOL> else : <EOL> dirtyChunkPositions = ( c for c in dirtyChunkPositions if self . containsChunk ( * c ) ) <EOL> dirtyChunkPositions = sorted ( dirtyChunkPositions ) <EOL> maxLightingChunks = getattr ( self , '<STR_LIT>' , <NUM_LIT> ) <EOL> log . info ( u"<STR_LIT>" . format ( len ( dirtyChunkPositions ) ) ) <EOL> chunkLists = [ dirtyChunkPositions ] <EOL> def reverseChunkPosition ( ( cx , cz ) ) : <EOL> return cz , cx <EOL> def splitChunkLists ( chunkLists ) : <EOL> newChunkLists = [ ] <EOL> for l in chunkLists : <EOL> smallX = l [ : len ( l ) / <NUM_LIT:2> ] <EOL> bigX = l [ len ( l ) / <NUM_LIT:2> : ] <EOL> smallX = sorted ( smallX , key = reverseChunkPosition ) <EOL> bigX = sorted ( bigX , key = reverseChunkPosition ) <EOL> newChunkLists . append ( smallX [ : len ( smallX ) / <NUM_LIT:2> ] ) <EOL> newChunkLists . append ( smallX [ len ( smallX ) / <NUM_LIT:2> : ] ) <EOL> newChunkLists . append ( bigX [ : len ( bigX ) / <NUM_LIT:2> ] ) <EOL> newChunkLists . append ( bigX [ len ( bigX ) / <NUM_LIT:2> : ] ) <EOL> return newChunkLists <EOL> while len ( chunkLists [ <NUM_LIT:0> ] ) > maxLightingChunks : <EOL> chunkLists = splitChunkLists ( chunkLists ) <EOL> if len ( chunkLists ) > <NUM_LIT:1> : <EOL> log . info ( u"<STR_LIT>" . format ( len ( chunkLists ) ) ) <EOL> estimatedTotals = [ len ( a ) * <NUM_LIT:32> for a in chunkLists ] <EOL> workDone = <NUM_LIT:0> <EOL> for i , dc in enumerate ( chunkLists ) : <EOL> log . info ( u"<STR_LIT>" . format ( i , len ( chunkLists ) ) ) <EOL> dc = sorted ( dc ) <EOL> workTotal = sum ( estimatedTotals ) <EOL> t = <NUM_LIT:0> <EOL> for c , t , p in self . _generateLightsIter ( dc ) : <EOL> yield c + workDone , t + workTotal - estimatedTotals [ i ] , p <EOL> estimatedTotals [ i ] = t <EOL> workDone += t <EOL> timeDelta = datetime . now ( ) - startTime <EOL> if len ( dirtyChunkPositions ) : <EOL> log . info ( u"<STR_LIT>" . format ( timeDelta , dirtyChunkPositions and timeDelta / len ( dirtyChunkPositions ) or <NUM_LIT:0> ) ) <EOL> return <EOL> def _generateLightsIter ( self , dirtyChunkPositions ) : <EOL> la = array ( self . materials . lightAbsorption ) <EOL> clip ( la , <NUM_LIT:1> , <NUM_LIT:15> , la ) <EOL> dirtyChunks = set ( self . getChunk ( * cPos ) for cPos in dirtyChunkPositions ) <EOL> workDone = <NUM_LIT:0> <EOL> workTotal = len ( dirtyChunks ) * <NUM_LIT> <EOL> progressInfo = ( u"<STR_LIT>" . format ( len ( dirtyChunks ) ) ) <EOL> log . info ( progressInfo ) <EOL> for i , chunk in enumerate ( dirtyChunks ) : <EOL> chunk . chunkChanged ( ) <EOL> yield i , workTotal , progressInfo <EOL> assert chunk . dirty and chunk . needsLighting <EOL> workDone += len ( dirtyChunks ) <EOL> workTotal = len ( dirtyChunks ) <EOL> for ch in list ( dirtyChunks ) : <EOL> cx , cz = ch . chunkPosition <EOL> for dx , dz in itertools . product ( ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ) , ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ) ) : <EOL> try : <EOL> ch = self . getChunk ( cx + dx , cz + dz ) <EOL> except ( ChunkNotPresent , ChunkMalformed ) : <EOL> continue <EOL> dirtyChunks . add ( ch ) <EOL> ch . dirty = True <EOL> dirtyChunks = sorted ( dirtyChunks , key = lambda x : x . chunkPosition ) <EOL> workTotal += len ( dirtyChunks ) * <NUM_LIT> <EOL> for i , chunk in enumerate ( dirtyChunks ) : <EOL> chunk . BlockLight [ : ] = self . materials . lightEmission [ chunk . Blocks ] <EOL> chunk . dirty = True <EOL> zeroChunk = ZeroChunk ( self . Height ) <EOL> zeroChunk . BlockLight [ : ] = <NUM_LIT:0> <EOL> zeroChunk . SkyLight [ : ] = <NUM_LIT:0> <EOL> startingDirtyChunks = dirtyChunks <EOL> oldLeftEdge = zeros ( ( <NUM_LIT:1> , <NUM_LIT:16> , self . Height ) , '<STR_LIT>' ) <EOL> oldBottomEdge = zeros ( ( <NUM_LIT:16> , <NUM_LIT:1> , self . Height ) , '<STR_LIT>' ) <EOL> oldChunk = zeros ( ( <NUM_LIT:16> , <NUM_LIT:16> , self . Height ) , '<STR_LIT>' ) <EOL> if self . dimNo in ( - <NUM_LIT:1> , <NUM_LIT:1> ) : <EOL> lights = ( "<STR_LIT>" , ) <EOL> else : <EOL> lights = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> log . info ( u"<STR_LIT>" ) <EOL> def clipLight ( light ) : <EOL> light . view ( '<STR_LIT>' ) . clip ( <NUM_LIT:0> , <NUM_LIT:15> , light ) <EOL> for j , light in enumerate ( lights ) : <EOL> zerochunkLight = getattr ( zeroChunk , light ) <EOL> newDirtyChunks = list ( startingDirtyChunks ) <EOL> work = <NUM_LIT:0> <EOL> for i in range ( <NUM_LIT> ) : <EOL> if len ( newDirtyChunks ) == <NUM_LIT:0> : <EOL> workTotal -= len ( startingDirtyChunks ) * ( <NUM_LIT> - i ) <EOL> break <EOL> progressInfo = u"<STR_LIT>" . format ( light , i , len ( newDirtyChunks ) ) <EOL> log . info ( progressInfo ) <EOL> newDirtyChunks = set ( newDirtyChunks ) <EOL> newDirtyChunks . discard ( zeroChunk ) <EOL> dirtyChunks = sorted ( newDirtyChunks , key = lambda x : x . chunkPosition ) <EOL> newDirtyChunks = list ( ) <EOL> for chunk in dirtyChunks : <EOL> ( cx , cz ) = chunk . chunkPosition <EOL> neighboringChunks = { } <EOL> for dir , dx , dz in ( ( FaceXDecreasing , - <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> ( FaceXIncreasing , <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> ( FaceZDecreasing , <NUM_LIT:0> , - <NUM_LIT:1> ) , <EOL> ( FaceZIncreasing , <NUM_LIT:0> , <NUM_LIT:1> ) ) : <EOL> try : <EOL> neighboringChunks [ dir ] = self . getChunk ( cx + dx , cz + dz ) <EOL> except ( ChunkNotPresent , ChunkMalformed ) : <EOL> neighboringChunks [ dir ] = zeroChunk <EOL> neighboringChunks [ dir ] . dirty = True <EOL> chunkLa = la [ chunk . Blocks ] <EOL> chunkLight = getattr ( chunk , light ) <EOL> oldChunk [ : ] = chunkLight [ : ] <EOL> nc = neighboringChunks [ FaceXDecreasing ] <EOL> ncLight = getattr ( nc , light ) <EOL> oldLeftEdge [ : ] = ncLight [ <NUM_LIT:15> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] <EOL> newlight = ( chunkLight [ <NUM_LIT:0> : <NUM_LIT:1> , : , : self . Height ] - la [ nc . Blocks [ <NUM_LIT:15> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( ncLight [ <NUM_LIT:15> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] , newlight , ncLight [ <NUM_LIT:15> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] ) <EOL> newlight = ( chunkLight [ <NUM_LIT:1> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] - chunkLa [ <NUM_LIT:0> : <NUM_LIT:15> , : , <NUM_LIT:0> : self . Height ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ <NUM_LIT:0> : <NUM_LIT:15> , : , <NUM_LIT:0> : self . Height ] , newlight , chunkLight [ <NUM_LIT:0> : <NUM_LIT:15> , : , <NUM_LIT:0> : self . Height ] ) <EOL> nc = neighboringChunks [ FaceXIncreasing ] <EOL> ncLight = getattr ( nc , light ) <EOL> newlight = ncLight [ <NUM_LIT:0> : <NUM_LIT:1> , : , : self . Height ] - chunkLa [ <NUM_LIT:15> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ <NUM_LIT:15> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] , newlight , chunkLight [ <NUM_LIT:15> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] ) <EOL> nc = neighboringChunks [ FaceXIncreasing ] <EOL> ncLight = getattr ( nc , light ) <EOL> newlight = ( chunkLight [ <NUM_LIT:15> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] - la [ nc . Blocks [ <NUM_LIT:0> : <NUM_LIT:1> , : , <NUM_LIT:0> : self . Height ] ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( ncLight [ <NUM_LIT:0> : <NUM_LIT:1> , : , <NUM_LIT:0> : self . Height ] , newlight , ncLight [ <NUM_LIT:0> : <NUM_LIT:1> , : , <NUM_LIT:0> : self . Height ] ) <EOL> newlight = ( chunkLight [ <NUM_LIT:0> : <NUM_LIT:15> , : , <NUM_LIT:0> : self . Height ] - chunkLa [ <NUM_LIT:1> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ <NUM_LIT:1> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] , newlight , chunkLight [ <NUM_LIT:1> : <NUM_LIT:16> , : , <NUM_LIT:0> : self . Height ] ) <EOL> nc = neighboringChunks [ FaceXDecreasing ] <EOL> ncLight = getattr ( nc , light ) <EOL> newlight = ncLight [ <NUM_LIT:15> : <NUM_LIT:16> , : , : self . Height ] - chunkLa [ <NUM_LIT:0> : <NUM_LIT:1> , : , <NUM_LIT:0> : self . Height ] <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ <NUM_LIT:0> : <NUM_LIT:1> , : , <NUM_LIT:0> : self . Height ] , newlight , chunkLight [ <NUM_LIT:0> : <NUM_LIT:1> , : , <NUM_LIT:0> : self . Height ] ) <EOL> zerochunkLight [ : ] = <NUM_LIT:0> <EOL> if ( oldLeftEdge != ncLight [ <NUM_LIT:15> : <NUM_LIT:16> , : , : self . Height ] ) . any ( ) : <EOL> newDirtyChunks . append ( nc ) <EOL> nc = neighboringChunks [ FaceZDecreasing ] <EOL> ncLight = getattr ( nc , light ) <EOL> oldBottomEdge [ : ] = ncLight [ : , <NUM_LIT:15> : <NUM_LIT:16> , : self . Height ] <EOL> newlight = ( chunkLight [ : , <NUM_LIT:0> : <NUM_LIT:1> , : self . Height ] - la [ nc . Blocks [ : , <NUM_LIT:15> : <NUM_LIT:16> , : self . Height ] ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( ncLight [ : , <NUM_LIT:15> : <NUM_LIT:16> , : self . Height ] , newlight , ncLight [ : , <NUM_LIT:15> : <NUM_LIT:16> , : self . Height ] ) <EOL> newlight = ( chunkLight [ : , <NUM_LIT:1> : <NUM_LIT:16> , : self . Height ] - chunkLa [ : , <NUM_LIT:0> : <NUM_LIT:15> , : self . Height ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ : , <NUM_LIT:0> : <NUM_LIT:15> , : self . Height ] , newlight , chunkLight [ : , <NUM_LIT:0> : <NUM_LIT:15> , : self . Height ] ) <EOL> nc = neighboringChunks [ FaceZIncreasing ] <EOL> ncLight = getattr ( nc , light ) <EOL> newlight = ncLight [ : , <NUM_LIT:0> : <NUM_LIT:1> , : self . Height ] - chunkLa [ : , <NUM_LIT:15> : <NUM_LIT:16> , <NUM_LIT:0> : self . Height ] <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ : , <NUM_LIT:15> : <NUM_LIT:16> , <NUM_LIT:0> : self . Height ] , newlight , chunkLight [ : , <NUM_LIT:15> : <NUM_LIT:16> , <NUM_LIT:0> : self . Height ] ) <EOL> nc = neighboringChunks [ FaceZIncreasing ] <EOL> ncLight = getattr ( nc , light ) <EOL> newlight = ( chunkLight [ : , <NUM_LIT:15> : <NUM_LIT:16> , : self . Height ] - la [ nc . Blocks [ : , <NUM_LIT:0> : <NUM_LIT:1> , : self . Height ] ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( ncLight [ : , <NUM_LIT:0> : <NUM_LIT:1> , : self . Height ] , newlight , ncLight [ : , <NUM_LIT:0> : <NUM_LIT:1> , : self . Height ] ) <EOL> newlight = ( chunkLight [ : , <NUM_LIT:0> : <NUM_LIT:15> , : self . Height ] - chunkLa [ : , <NUM_LIT:1> : <NUM_LIT:16> , : self . Height ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ : , <NUM_LIT:1> : <NUM_LIT:16> , : self . Height ] , newlight , chunkLight [ : , <NUM_LIT:1> : <NUM_LIT:16> , : self . Height ] ) <EOL> nc = neighboringChunks [ FaceZDecreasing ] <EOL> ncLight = getattr ( nc , light ) <EOL> newlight = ncLight [ : , <NUM_LIT:15> : <NUM_LIT:16> , : self . Height ] - chunkLa [ : , <NUM_LIT:0> : <NUM_LIT:1> , <NUM_LIT:0> : self . Height ] <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ : , <NUM_LIT:0> : <NUM_LIT:1> , <NUM_LIT:0> : self . Height ] , newlight , chunkLight [ : , <NUM_LIT:0> : <NUM_LIT:1> , <NUM_LIT:0> : self . Height ] ) <EOL> zerochunkLight [ : ] = <NUM_LIT:0> <EOL> if ( oldBottomEdge != ncLight [ : , <NUM_LIT:15> : <NUM_LIT:16> , : self . Height ] ) . any ( ) : <EOL> newDirtyChunks . append ( nc ) <EOL> newlight = ( chunkLight [ : , : , <NUM_LIT:0> : self . Height - <NUM_LIT:1> ] - chunkLa [ : , : , <NUM_LIT:1> : self . Height ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ : , : , <NUM_LIT:1> : self . Height ] , newlight , chunkLight [ : , : , <NUM_LIT:1> : self . Height ] ) <EOL> newlight = ( chunkLight [ : , : , <NUM_LIT:1> : self . Height ] - chunkLa [ : , : , <NUM_LIT:0> : self . Height - <NUM_LIT:1> ] ) <EOL> clipLight ( newlight ) <EOL> maximum ( chunkLight [ : , : , <NUM_LIT:0> : self . Height - <NUM_LIT:1> ] , newlight , chunkLight [ : , : , <NUM_LIT:0> : self . Height - <NUM_LIT:1> ] ) <EOL> if ( oldChunk != chunkLight ) . any ( ) : <EOL> newDirtyChunks . append ( chunk ) <EOL> work += <NUM_LIT:1> <EOL> yield workDone + work , workTotal , progressInfo <EOL> workDone += work <EOL> workTotal -= len ( startingDirtyChunks ) <EOL> workTotal += work <EOL> work = <NUM_LIT:0> <EOL> for ch in startingDirtyChunks : <EOL> ch . needsLighting = False <EOL> def TagProperty ( tagName , tagType , default_or_func = None ) : <EOL> def getter ( self ) : <EOL> if tagName not in self . root_tag [ "<STR_LIT>" ] : <EOL> if hasattr ( default_or_func , "<STR_LIT>" ) : <EOL> default = default_or_func ( self ) <EOL> else : <EOL> default = default_or_func <EOL> self . root_tag [ "<STR_LIT>" ] [ tagName ] = tagType ( default ) <EOL> return self . root_tag [ "<STR_LIT>" ] [ tagName ] . value <EOL> def setter ( self , val ) : <EOL> self . root_tag [ "<STR_LIT>" ] [ tagName ] = tagType ( value = val ) <EOL> return property ( getter , setter ) <EOL> class AnvilWorldFolder ( object ) : <EOL> def __init__ ( self , filename ) : <EOL> if not os . path . exists ( filename ) : <EOL> os . mkdir ( filename ) <EOL> elif not os . path . isdir ( filename ) : <EOL> raise IOError , "<STR_LIT>" % filename <EOL> self . filename = filename <EOL> self . regionFiles = { } <EOL> def getFilePath ( self , path ) : <EOL> path = path . replace ( "<STR_LIT:/>" , os . path . sep ) <EOL> return os . path . join ( self . filename , path ) <EOL> def getFolderPath ( self , path ) : <EOL> path = self . getFilePath ( path ) <EOL> if not os . path . exists ( path ) : <EOL> os . makedirs ( path ) <EOL> return path <EOL> def getRegionFilename ( self , rx , rz ) : <EOL> return os . path . join ( self . getFolderPath ( "<STR_LIT>" ) , "<STR_LIT>" % ( rx , rz , "<STR_LIT>" ) ) <EOL> def getRegionFile ( self , rx , rz ) : <EOL> regionFile = self . regionFiles . get ( ( rx , rz ) ) <EOL> if regionFile : <EOL> return regionFile <EOL> regionFile = MCRegionFile ( self . getRegionFilename ( rx , rz ) , ( rx , rz ) ) <EOL> self . regionFiles [ rx , rz ] = regionFile <EOL> return regionFile <EOL> def getRegionForChunk ( self , cx , cz ) : <EOL> rx = cx >> <NUM_LIT:5> <EOL> rz = cz >> <NUM_LIT:5> <EOL> return self . getRegionFile ( rx , rz ) <EOL> def closeRegions ( self ) : <EOL> for rf in self . regionFiles . values ( ) : <EOL> rf . close ( ) <EOL> self . regionFiles = { } <EOL> def tryLoadRegionFile ( self , filepath ) : <EOL> filename = os . path . basename ( filepath ) <EOL> bits = filename . split ( '<STR_LIT:.>' ) <EOL> if len ( bits ) < <NUM_LIT:4> or bits [ <NUM_LIT:0> ] != '<STR_LIT:r>' or bits [ <NUM_LIT:3> ] != "<STR_LIT>" : <EOL> return None <EOL> try : <EOL> rx , rz = map ( int , bits [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> except ValueError : <EOL> return None <EOL> return MCRegionFile ( filepath , ( rx , rz ) ) <EOL> def findRegionFiles ( self ) : <EOL> regionDir = self . getFolderPath ( "<STR_LIT>" ) <EOL> regionFiles = os . listdir ( regionDir ) <EOL> for filename in regionFiles : <EOL> yield os . path . join ( regionDir , filename ) <EOL> def listChunks ( self ) : <EOL> chunks = set ( ) <EOL> for filepath in self . findRegionFiles ( ) : <EOL> regionFile = self . tryLoadRegionFile ( filepath ) <EOL> if regionFile is None : <EOL> continue <EOL> if regionFile . offsets . any ( ) : <EOL> rx , rz = regionFile . regionCoords <EOL> self . regionFiles [ rx , rz ] = regionFile <EOL> for index , offset in enumerate ( regionFile . offsets ) : <EOL> if offset : <EOL> cx = index & <NUM_LIT> <EOL> cz = index >> <NUM_LIT:5> <EOL> cx += rx << <NUM_LIT:5> <EOL> cz += rz << <NUM_LIT:5> <EOL> chunks . add ( ( cx , cz ) ) <EOL> else : <EOL> log . info ( u"<STR_LIT>" . format ( filepath ) ) <EOL> regionFile . close ( ) <EOL> os . unlink ( regionFile . path ) <EOL> return chunks <EOL> def containsChunk ( self , cx , cz ) : <EOL> rx = cx >> <NUM_LIT:5> <EOL> rz = cz >> <NUM_LIT:5> <EOL> if not os . path . exists ( self . getRegionFilename ( rx , rz ) ) : <EOL> return False <EOL> return self . getRegionForChunk ( cx , cz ) . containsChunk ( cx , cz ) <EOL> def deleteChunk ( self , cx , cz ) : <EOL> r = cx >> <NUM_LIT:5> , cz >> <NUM_LIT:5> <EOL> rf = self . getRegionFile ( * r ) <EOL> if rf : <EOL> rf . setOffset ( cx & <NUM_LIT> , cz & <NUM_LIT> , <NUM_LIT:0> ) <EOL> if ( rf . offsets == <NUM_LIT:0> ) . all ( ) : <EOL> rf . close ( ) <EOL> os . unlink ( rf . path ) <EOL> del self . regionFiles [ r ] <EOL> def readChunk ( self , cx , cz ) : <EOL> if not self . containsChunk ( cx , cz ) : <EOL> raise ChunkNotPresent ( ( cx , cz ) ) <EOL> return self . getRegionForChunk ( cx , cz ) . readChunk ( cx , cz ) <EOL> def saveChunk ( self , cx , cz , data ) : <EOL> regionFile = self . getRegionForChunk ( cx , cz ) <EOL> regionFile . saveChunk ( cx , cz , data ) <EOL> def copyChunkFrom ( self , worldFolder , cx , cz ) : <EOL> fromRF = worldFolder . getRegionForChunk ( cx , cz ) <EOL> rf = self . getRegionForChunk ( cx , cz ) <EOL> rf . copyChunkFrom ( fromRF , cx , cz ) <EOL> class MCInfdevOldLevel ( ChunkedLevelMixin , EntityLevel ) : <EOL> def __init__ ( self , filename = None , create = False , random_seed = None , last_played = None , readonly = False ) : <EOL> """<STR_LIT>""" <EOL> self . Length = <NUM_LIT:0> <EOL> self . Width = <NUM_LIT:0> <EOL> self . Height = <NUM_LIT> <EOL> self . playerTagCache = { } <EOL> self . players = [ ] <EOL> assert not ( create and readonly ) <EOL> if os . path . basename ( filename ) in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> filename = os . path . dirname ( filename ) <EOL> if not os . path . exists ( filename ) : <EOL> if not create : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> os . mkdir ( filename ) <EOL> if not os . path . isdir ( filename ) : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> self . worldFolder = AnvilWorldFolder ( filename ) <EOL> self . filename = self . worldFolder . getFilePath ( "<STR_LIT>" ) <EOL> self . readonly = readonly <EOL> if not readonly : <EOL> self . acquireSessionLock ( ) <EOL> workFolderPath = self . worldFolder . getFolderPath ( "<STR_LIT>" ) <EOL> if os . path . exists ( workFolderPath ) : <EOL> shutil . rmtree ( workFolderPath , True ) <EOL> self . unsavedWorkFolder = AnvilWorldFolder ( workFolderPath ) <EOL> self . _loadedChunks = weakref . WeakValueDictionary ( ) <EOL> self . _loadedChunkData = { } <EOL> self . chunksNeedingLighting = set ( ) <EOL> self . _allChunks = None <EOL> self . dimensions = { } <EOL> self . loadLevelDat ( create , random_seed , last_played ) <EOL> assert self . version == self . VERSION_ANVIL , "<STR_LIT>" <EOL> self . playersFolder = self . worldFolder . getFolderPath ( "<STR_LIT>" ) <EOL> self . players = [ x [ : - <NUM_LIT:4> ] for x in os . listdir ( self . playersFolder ) if x . endswith ( "<STR_LIT>" ) ] <EOL> if "<STR_LIT>" in self . root_tag [ "<STR_LIT>" ] : <EOL> self . players . append ( "<STR_LIT>" ) <EOL> self . preloadDimensions ( ) <EOL> def _create ( self , filename , random_seed , last_played ) : <EOL> root_tag = nbt . TAG_Compound ( ) <EOL> root_tag [ "<STR_LIT>" ] = nbt . TAG_Compound ( ) <EOL> root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] = nbt . TAG_Int ( <NUM_LIT:0> ) <EOL> root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] = nbt . TAG_Int ( <NUM_LIT:2> ) <EOL> root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] = nbt . TAG_Int ( <NUM_LIT:0> ) <EOL> if last_played is None : <EOL> last_played = long ( time . time ( ) * <NUM_LIT:1000> ) <EOL> if random_seed is None : <EOL> random_seed = long ( random . random ( ) * <NUM_LIT> L ) - <NUM_LIT> L <EOL> self . root_tag = root_tag <EOL> root_tag [ "<STR_LIT>" ] [ '<STR_LIT:version>' ] = nbt . TAG_Int ( self . VERSION_ANVIL ) <EOL> self . LastPlayed = long ( last_played ) <EOL> self . RandomSeed = long ( random_seed ) <EOL> self . SizeOnDisk = <NUM_LIT:0> <EOL> self . Time = <NUM_LIT:1> <EOL> self . LevelName = os . path . basename ( self . worldFolder . filename ) <EOL> self . createPlayer ( "<STR_LIT>" ) <EOL> def acquireSessionLock ( self ) : <EOL> lockfile = self . worldFolder . getFilePath ( "<STR_LIT>" ) <EOL> self . initTime = int ( time . time ( ) * <NUM_LIT:1000> ) <EOL> with file ( lockfile , "<STR_LIT:wb>" ) as f : <EOL> f . write ( struct . pack ( "<STR_LIT>" , self . initTime ) ) <EOL> f . flush ( ) <EOL> os . fsync ( f . fileno ( ) ) <EOL> def checkSessionLock ( self ) : <EOL> if self . readonly : <EOL> raise SessionLockLost , "<STR_LIT>" <EOL> lockfile = self . worldFolder . getFilePath ( "<STR_LIT>" ) <EOL> try : <EOL> ( lock , ) = struct . unpack ( "<STR_LIT>" , file ( lockfile , "<STR_LIT:rb>" ) . read ( ) ) <EOL> except struct . error : <EOL> lock = - <NUM_LIT:1> <EOL> if lock != self . initTime : <EOL> raise SessionLockLost , "<STR_LIT>" <EOL> def loadLevelDat ( self , create = False , random_seed = None , last_played = None ) : <EOL> if create : <EOL> self . _create ( self . filename , random_seed , last_played ) <EOL> self . saveInPlace ( ) <EOL> else : <EOL> try : <EOL> self . root_tag = nbt . load ( self . filename ) <EOL> except Exception , e : <EOL> filename_old = self . worldFolder . getFilePath ( "<STR_LIT>" ) <EOL> log . info ( "<STR_LIT>" . format ( e ) ) <EOL> try : <EOL> self . root_tag = nbt . load ( filename_old ) <EOL> log . info ( "<STR_LIT>" ) <EOL> self . saveInPlace ( ) <EOL> except Exception , e : <EOL> traceback . print_exc ( ) <EOL> print repr ( e ) <EOL> log . info ( "<STR_LIT>" ) <EOL> self . _create ( self . filename , random_seed , last_played ) <EOL> def saveInPlace ( self ) : <EOL> if self . readonly : <EOL> raise IOError , "<STR_LIT>" <EOL> self . checkSessionLock ( ) <EOL> for level in self . dimensions . itervalues ( ) : <EOL> level . saveInPlace ( True ) <EOL> dirtyChunkCount = <NUM_LIT:0> <EOL> for chunk in self . _loadedChunkData . itervalues ( ) : <EOL> cx , cz = chunk . chunkPosition <EOL> if chunk . dirty : <EOL> data = chunk . savedTagData ( ) <EOL> dirtyChunkCount += <NUM_LIT:1> <EOL> self . worldFolder . saveChunk ( cx , cz , data ) <EOL> chunk . dirty = False <EOL> for cx , cz in self . unsavedWorkFolder . listChunks ( ) : <EOL> if ( cx , cz ) not in self . _loadedChunkData : <EOL> data = self . unsavedWorkFolder . readChunk ( cx , cz ) <EOL> self . worldFolder . saveChunk ( cx , cz , data ) <EOL> dirtyChunkCount += <NUM_LIT:1> <EOL> self . unsavedWorkFolder . closeRegions ( ) <EOL> shutil . rmtree ( self . unsavedWorkFolder . filename , True ) <EOL> if not os . path . exists ( self . unsavedWorkFolder . filename ) : <EOL> os . mkdir ( self . unsavedWorkFolder . filename ) <EOL> for path , tag in self . playerTagCache . iteritems ( ) : <EOL> tag . save ( path ) <EOL> self . playerTagCache . clear ( ) <EOL> self . root_tag . save ( self . filename ) <EOL> log . info ( u"<STR_LIT>" . format ( dirtyChunkCount , self . dimNo ) ) <EOL> def unload ( self ) : <EOL> """<STR_LIT>""" <EOL> self . worldFolder . closeRegions ( ) <EOL> if not self . readonly : <EOL> self . unsavedWorkFolder . closeRegions ( ) <EOL> self . _allChunks = None <EOL> self . _loadedChunks . clear ( ) <EOL> self . _loadedChunkData . clear ( ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . unload ( ) <EOL> try : <EOL> self . checkSessionLock ( ) <EOL> shutil . rmtree ( self . unsavedWorkFolder . filename , True ) <EOL> except SessionLockLost : <EOL> pass <EOL> loadedChunkLimit = <NUM_LIT> <EOL> GAMETYPE_SURVIVAL = <NUM_LIT:0> <EOL> GAMETYPE_CREATIVE = <NUM_LIT:1> <EOL> VERSION_MCR = <NUM_LIT> <EOL> VERSION_ANVIL = <NUM_LIT> <EOL> materials = alphaMaterials <EOL> isInfinite = True <EOL> parentWorld = None <EOL> dimNo = <NUM_LIT:0> <EOL> Height = <NUM_LIT> <EOL> _bounds = None <EOL> SizeOnDisk = TagProperty ( '<STR_LIT>' , nbt . TAG_Long , <NUM_LIT:0> ) <EOL> RandomSeed = TagProperty ( '<STR_LIT>' , nbt . TAG_Long , <NUM_LIT:0> ) <EOL> Time = TagProperty ( '<STR_LIT>' , nbt . TAG_Long , <NUM_LIT:0> ) <EOL> LastPlayed = TagProperty ( '<STR_LIT>' , nbt . TAG_Long , lambda self : long ( time . time ( ) * <NUM_LIT:1000> ) ) <EOL> LevelName = TagProperty ( '<STR_LIT>' , nbt . TAG_String , lambda self : self . displayName ) <EOL> MapFeatures = TagProperty ( '<STR_LIT>' , nbt . TAG_Byte , <NUM_LIT:1> ) <EOL> GameType = TagProperty ( '<STR_LIT>' , nbt . TAG_Int , <NUM_LIT:0> ) <EOL> version = TagProperty ( '<STR_LIT:version>' , nbt . TAG_Int , VERSION_ANVIL ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % os . path . basename ( self . worldFolder . filename ) <EOL> @ property <EOL> def displayName ( self ) : <EOL> shortname = os . path . basename ( os . path . dirname ( self . filename ) ) <EOL> return shortname <EOL> @ property <EOL> def bounds ( self ) : <EOL> if self . _bounds is None : <EOL> self . _bounds = self . getWorldBounds ( ) <EOL> return self . _bounds <EOL> def getWorldBounds ( self ) : <EOL> if self . chunkCount == <NUM_LIT:0> : <EOL> return BoundingBox ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> allChunks = array ( list ( self . allChunks ) ) <EOL> mincx = ( allChunks [ : , <NUM_LIT:0> ] ) . min ( ) <EOL> maxcx = ( allChunks [ : , <NUM_LIT:0> ] ) . max ( ) <EOL> mincz = ( allChunks [ : , <NUM_LIT:1> ] ) . min ( ) <EOL> maxcz = ( allChunks [ : , <NUM_LIT:1> ] ) . max ( ) <EOL> origin = ( mincx << <NUM_LIT:4> , <NUM_LIT:0> , mincz << <NUM_LIT:4> ) <EOL> size = ( ( maxcx - mincx + <NUM_LIT:1> ) << <NUM_LIT:4> , self . Height , ( maxcz - mincz + <NUM_LIT:1> ) << <NUM_LIT:4> ) <EOL> return BoundingBox ( origin , size ) <EOL> @ property <EOL> def size ( self ) : <EOL> return self . bounds . size <EOL> @ classmethod <EOL> def _isLevel ( cls , filename ) : <EOL> if os . path . exists ( os . path . join ( filename , "<STR_LIT>" ) ) : <EOL> return False <EOL> if not os . path . isdir ( filename ) : <EOL> f = os . path . basename ( filename ) <EOL> if f not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> return False <EOL> filename = os . path . dirname ( filename ) <EOL> files = os . listdir ( filename ) <EOL> if "<STR_LIT>" in files or "<STR_LIT>" in files : <EOL> return True <EOL> return False <EOL> def preloadDimensions ( self ) : <EOL> worldDirs = os . listdir ( self . worldFolder . filename ) <EOL> for dirname in worldDirs : <EOL> if dirname . startswith ( "<STR_LIT>" ) : <EOL> try : <EOL> dimNo = int ( dirname [ <NUM_LIT:3> : ] ) <EOL> log . info ( "<STR_LIT>" . format ( dirname ) ) <EOL> dim = MCAlphaDimension ( self , dimNo ) <EOL> self . dimensions [ dimNo ] = dim <EOL> except Exception , e : <EOL> log . error ( u"<STR_LIT>" . format ( dirname , e ) ) <EOL> def getDimension ( self , dimNo ) : <EOL> if self . dimNo != <NUM_LIT:0> : <EOL> return self . parentWorld . getDimension ( dimNo ) <EOL> if dimNo in self . dimensions : <EOL> return self . dimensions [ dimNo ] <EOL> dim = MCAlphaDimension ( self , dimNo , create = True ) <EOL> self . dimensions [ dimNo ] = dim <EOL> return dim <EOL> def preloadChunkPositions ( self ) : <EOL> log . info ( u"<STR_LIT>" ) <EOL> self . _allChunks = self . worldFolder . listChunks ( ) <EOL> if not self . readonly : <EOL> self . _allChunks . update ( self . unsavedWorkFolder . listChunks ( ) ) <EOL> self . _allChunks . update ( self . _loadedChunkData . iterkeys ( ) ) <EOL> def getRegionForChunk ( self , cx , cz ) : <EOL> return self . worldFolder . getRegionFile ( cx , cz ) <EOL> def dirhash ( self , n ) : <EOL> return self . dirhashes [ n % <NUM_LIT:64> ] <EOL> def _dirhash ( self ) : <EOL> n = self <EOL> n = n % <NUM_LIT:64> <EOL> s = u"<STR_LIT>" <EOL> if n >= <NUM_LIT> : <EOL> s += u"<STR_LIT:1>" <EOL> n -= <NUM_LIT> <EOL> s += u"<STR_LIT>" [ n ] <EOL> return s <EOL> dirhashes = [ _dirhash ( n ) for n in range ( <NUM_LIT:64> ) ] <EOL> def _oldChunkFilename ( self , cx , cz ) : <EOL> return self . worldFolder . getFilePath ( "<STR_LIT>" % ( self . dirhash ( cx ) , self . dirhash ( cz ) , base36 ( cx ) , base36 ( cz ) ) ) <EOL> def extractChunksInBox ( self , box , parentFolder ) : <EOL> for cx , cz in box . chunkPositions : <EOL> if self . containsChunk ( cx , cz ) : <EOL> self . extractChunk ( cx , cz , parentFolder ) <EOL> def extractChunk ( self , cx , cz , parentFolder ) : <EOL> if not os . path . exists ( parentFolder ) : <EOL> os . mkdir ( parentFolder ) <EOL> chunkFilename = self . _oldChunkFilename ( cx , cz ) <EOL> outputFile = os . path . join ( parentFolder , os . path . basename ( chunkFilename ) ) <EOL> chunk = self . getChunk ( cx , cz ) <EOL> chunk . root_tag . save ( outputFile ) <EOL> @ property <EOL> def chunkCount ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _allChunks is None : <EOL> self . preloadChunkPositions ( ) <EOL> return len ( self . _allChunks ) <EOL> @ property <EOL> def allChunks ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _allChunks is None : <EOL> self . preloadChunkPositions ( ) <EOL> return self . _allChunks . __iter__ ( ) <EOL> def copyChunkFrom ( self , world , cx , cz ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( world , MCInfdevOldLevel ) <EOL> if self . readonly : <EOL> raise IOError , "<STR_LIT>" <EOL> self . checkSessionLock ( ) <EOL> destChunk = self . _loadedChunks . get ( ( cx , cz ) ) <EOL> sourceChunk = world . _loadedChunks . get ( ( cx , cz ) ) <EOL> if sourceChunk : <EOL> if destChunk : <EOL> log . debug ( "<STR_LIT>" ) <EOL> self . copyBlocksFrom ( world , destChunk . bounds , destChunk . bounds . origin ) <EOL> return <EOL> else : <EOL> log . debug ( "<STR_LIT>" ) <EOL> self . _loadedChunkData . pop ( ( cx , cz ) , None ) <EOL> self . unsavedWorkFolder . saveChunk ( cx , cz , sourceChunk . savedTagData ( ) ) <EOL> return <EOL> else : <EOL> if destChunk : <EOL> log . debug ( "<STR_LIT>" ) <EOL> self . copyBlocksFrom ( world , destChunk . bounds , destChunk . bounds . origin ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" ) <EOL> self . _loadedChunkData . pop ( ( cx , cz ) , None ) <EOL> chunkData = world . _loadedChunkData . pop ( ( cx , cz ) , None ) <EOL> if chunkData and chunkData . dirty : <EOL> data = chunkData . savedTagData ( ) <EOL> world . unsavedWorkFolder . saveChunk ( cx , cz , data ) <EOL> if world . unsavedWorkFolder . containsChunk ( cx , cz ) : <EOL> sourceFolder = world . unsavedWorkFolder <EOL> else : <EOL> sourceFolder = world . worldFolder <EOL> self . unsavedWorkFolder . copyChunkFrom ( sourceFolder , cx , cz ) <EOL> def _getChunkBytes ( self , cx , cz ) : <EOL> if not self . readonly and self . unsavedWorkFolder . containsChunk ( cx , cz ) : <EOL> return self . unsavedWorkFolder . readChunk ( cx , cz ) <EOL> else : <EOL> return self . worldFolder . readChunk ( cx , cz ) <EOL> def _getChunkData ( self , cx , cz ) : <EOL> chunkData = self . _loadedChunkData . get ( ( cx , cz ) ) <EOL> if chunkData is not None : return chunkData <EOL> try : <EOL> data = self . _getChunkBytes ( cx , cz ) <EOL> root_tag = nbt . load ( buf = data ) <EOL> chunkData = AnvilChunkData ( self , ( cx , cz ) , root_tag ) <EOL> except ( MemoryError , ChunkNotPresent ) : <EOL> raise <EOL> except Exception , e : <EOL> raise ChunkMalformed , "<STR_LIT>" . format ( ( cx , cz ) , e ) , sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> if not self . readonly and self . unsavedWorkFolder . containsChunk ( cx , cz ) : <EOL> chunkData . dirty = True <EOL> self . _storeLoadedChunkData ( chunkData ) <EOL> return chunkData <EOL> def _storeLoadedChunkData ( self , chunkData ) : <EOL> if len ( self . _loadedChunkData ) > self . loadedChunkLimit : <EOL> if not self . readonly : <EOL> self . checkSessionLock ( ) <EOL> for ( ocx , ocz ) , oldChunkData in self . _loadedChunkData . items ( ) : <EOL> if ( ocx , ocz ) not in self . _loadedChunks : <EOL> if oldChunkData . dirty and not self . readonly : <EOL> data = oldChunkData . savedTagData ( ) <EOL> self . unsavedWorkFolder . saveChunk ( ocx , ocz , data ) <EOL> del self . _loadedChunkData [ ocx , ocz ] <EOL> break <EOL> self . _loadedChunkData [ chunkData . chunkPosition ] = chunkData <EOL> def getChunk ( self , cx , cz ) : <EOL> """<STR_LIT>""" <EOL> chunk = self . _loadedChunks . get ( ( cx , cz ) ) <EOL> if chunk is not None : <EOL> return chunk <EOL> chunkData = self . _getChunkData ( cx , cz ) <EOL> chunk = AnvilChunk ( chunkData ) <EOL> self . _loadedChunks [ cx , cz ] = chunk <EOL> return chunk <EOL> def markDirtyChunk ( self , cx , cz ) : <EOL> self . getChunk ( cx , cz ) . chunkChanged ( ) <EOL> def markDirtyBox ( self , box ) : <EOL> for cx , cz in box . chunkPositions : <EOL> self . markDirtyChunk ( cx , cz ) <EOL> def listDirtyChunks ( self ) : <EOL> for cPos , chunkData in self . _loadedChunkData . iteritems ( ) : <EOL> if chunkData . dirty : <EOL> yield cPos <EOL> def heightMapAt ( self , x , z ) : <EOL> zc = z >> <NUM_LIT:4> <EOL> xc = x >> <NUM_LIT:4> <EOL> xInChunk = x & <NUM_LIT> <EOL> zInChunk = z & <NUM_LIT> <EOL> ch = self . getChunk ( xc , zc ) <EOL> heightMap = ch . HeightMap <EOL> return heightMap [ zInChunk , xInChunk ] <EOL> def addEntity ( self , entityTag ) : <EOL> assert isinstance ( entityTag , nbt . TAG_Compound ) <EOL> x , y , z = map ( lambda x : int ( floor ( x ) ) , Entity . pos ( entityTag ) ) <EOL> try : <EOL> chunk = self . getChunk ( x >> <NUM_LIT:4> , z >> <NUM_LIT:4> ) <EOL> except ( ChunkNotPresent , ChunkMalformed ) : <EOL> return None <EOL> chunk . addEntity ( entityTag ) <EOL> chunk . dirty = True <EOL> def tileEntityAt ( self , x , y , z ) : <EOL> chunk = self . getChunk ( x >> <NUM_LIT:4> , z >> <NUM_LIT:4> ) <EOL> return chunk . tileEntityAt ( x , y , z ) <EOL> def addTileEntity ( self , tileEntityTag ) : <EOL> assert isinstance ( tileEntityTag , nbt . TAG_Compound ) <EOL> if not '<STR_LIT:x>' in tileEntityTag : <EOL> return <EOL> x , y , z = TileEntity . pos ( tileEntityTag ) <EOL> try : <EOL> chunk = self . getChunk ( x >> <NUM_LIT:4> , z >> <NUM_LIT:4> ) <EOL> except ( ChunkNotPresent , ChunkMalformed ) : <EOL> return <EOL> chunk . addTileEntity ( tileEntityTag ) <EOL> chunk . dirty = True <EOL> def getEntitiesInBox ( self , box ) : <EOL> entities = [ ] <EOL> for chunk , slices , point in self . getChunkSlices ( box ) : <EOL> entities += chunk . getEntitiesInBox ( box ) <EOL> return entities <EOL> def removeEntitiesInBox ( self , box ) : <EOL> count = <NUM_LIT:0> <EOL> for chunk , slices , point in self . getChunkSlices ( box ) : <EOL> count += chunk . removeEntitiesInBox ( box ) <EOL> log . info ( "<STR_LIT>" . format ( count ) ) <EOL> return count <EOL> def removeTileEntitiesInBox ( self , box ) : <EOL> count = <NUM_LIT:0> <EOL> for chunk , slices , point in self . getChunkSlices ( box ) : <EOL> count += chunk . removeTileEntitiesInBox ( box ) <EOL> log . info ( "<STR_LIT>" . format ( count ) ) <EOL> return count <EOL> def containsChunk ( self , cx , cz ) : <EOL> if self . _allChunks is not None : <EOL> return ( cx , cz ) in self . _allChunks <EOL> if ( cx , cz ) in self . _loadedChunkData : <EOL> return True <EOL> return self . worldFolder . containsChunk ( cx , cz ) <EOL> def containsPoint ( self , x , y , z ) : <EOL> if y < <NUM_LIT:0> or y > <NUM_LIT> : <EOL> return False <EOL> return self . containsChunk ( x >> <NUM_LIT:4> , z >> <NUM_LIT:4> ) <EOL> def createChunk ( self , cx , cz ) : <EOL> if self . containsChunk ( cx , cz ) : <EOL> raise ValueError ( "<STR_LIT>" . format ( self , ( cx , cz ) ) ) <EOL> if self . _allChunks is not None : <EOL> self . _allChunks . add ( ( cx , cz ) ) <EOL> self . _storeLoadedChunkData ( AnvilChunkData ( self , ( cx , cz ) , create = True ) ) <EOL> self . _bounds = None <EOL> def createChunks ( self , chunks ) : <EOL> i = <NUM_LIT:0> <EOL> ret = [ ] <EOL> for cx , cz in chunks : <EOL> i += <NUM_LIT:1> <EOL> if not self . containsChunk ( cx , cz ) : <EOL> ret . append ( ( cx , cz ) ) <EOL> self . createChunk ( cx , cz ) <EOL> assert self . containsChunk ( cx , cz ) , "<STR_LIT>" . format ( ( cx , cz ) ) <EOL> if i % <NUM_LIT:100> == <NUM_LIT:0> : <EOL> log . info ( u"<STR_LIT>" . format ( i ) ) <EOL> log . info ( "<STR_LIT>" . format ( len ( ret ) ) ) <EOL> return ret <EOL> def createChunksInBox ( self , box ) : <EOL> log . info ( u"<STR_LIT>" . format ( ( box . maxcx - box . mincx ) * ( box . maxcz - box . mincz ) , ( ( box . mincx , box . mincz ) , ( box . maxcx , box . maxcz ) ) ) ) <EOL> return self . createChunks ( box . chunkPositions ) <EOL> def deleteChunk ( self , cx , cz ) : <EOL> self . worldFolder . deleteChunk ( cx , cz ) <EOL> if self . _allChunks is not None : <EOL> self . _allChunks . discard ( ( cx , cz ) ) <EOL> self . _bounds = None <EOL> def deleteChunksInBox ( self , box ) : <EOL> log . info ( u"<STR_LIT>" . format ( ( box . maxcx - box . mincx ) * ( box . maxcz - box . mincz ) , ( ( box . mincx , box . mincz ) , ( box . maxcx , box . maxcz ) ) ) ) <EOL> i = <NUM_LIT:0> <EOL> ret = [ ] <EOL> for cx , cz in itertools . product ( xrange ( box . mincx , box . maxcx ) , xrange ( box . mincz , box . maxcz ) ) : <EOL> i += <NUM_LIT:1> <EOL> if self . containsChunk ( cx , cz ) : <EOL> self . deleteChunk ( cx , cz ) <EOL> ret . append ( ( cx , cz ) ) <EOL> assert not self . containsChunk ( cx , cz ) , "<STR_LIT>" . format ( ( cx , cz ) ) <EOL> if i % <NUM_LIT:100> == <NUM_LIT:0> : <EOL> log . info ( u"<STR_LIT>" . format ( i ) ) <EOL> return ret <EOL> def playerSpawnPosition ( self , player = None ) : <EOL> """<STR_LIT>""" <EOL> dataTag = self . root_tag [ "<STR_LIT>" ] <EOL> if player is None : <EOL> playerSpawnTag = dataTag <EOL> else : <EOL> playerSpawnTag = self . getPlayerTag ( player ) <EOL> return [ playerSpawnTag . get ( i , dataTag [ i ] ) . value for i in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> def setPlayerSpawnPosition ( self , pos , player = None ) : <EOL> """<STR_LIT>""" <EOL> if player is None : <EOL> playerSpawnTag = self . root_tag [ "<STR_LIT>" ] <EOL> else : <EOL> playerSpawnTag = self . getPlayerTag ( player ) <EOL> for name , val in zip ( ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , pos ) : <EOL> playerSpawnTag [ name ] = nbt . TAG_Int ( val ) <EOL> def getPlayerPath ( self , player ) : <EOL> assert player != "<STR_LIT>" <EOL> return os . path . join ( self . playersFolder , "<STR_LIT>" % player ) <EOL> def getPlayerTag ( self , player = "<STR_LIT>" ) : <EOL> if player == "<STR_LIT>" : <EOL> if player in self . root_tag [ "<STR_LIT>" ] : <EOL> return self . root_tag [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> raise PlayerNotFound ( player ) <EOL> else : <EOL> playerFilePath = self . getPlayerPath ( player ) <EOL> if os . path . exists ( playerFilePath ) : <EOL> playerTag = self . playerTagCache . get ( playerFilePath ) <EOL> if playerTag is None : <EOL> playerTag = nbt . load ( playerFilePath ) <EOL> self . playerTagCache [ playerFilePath ] = playerTag <EOL> return playerTag <EOL> else : <EOL> raise PlayerNotFound ( player ) <EOL> def getPlayerDimension ( self , player = "<STR_LIT>" ) : <EOL> playerTag = self . getPlayerTag ( player ) <EOL> if "<STR_LIT>" not in playerTag : <EOL> return <NUM_LIT:0> <EOL> return playerTag [ "<STR_LIT>" ] . value <EOL> def setPlayerDimension ( self , d , player = "<STR_LIT>" ) : <EOL> playerTag = self . getPlayerTag ( player ) <EOL> if "<STR_LIT>" not in playerTag : <EOL> playerTag [ "<STR_LIT>" ] = nbt . TAG_Int ( <NUM_LIT:0> ) <EOL> playerTag [ "<STR_LIT>" ] . value = d <EOL> def setPlayerPosition ( self , ( x , y , z ) , player = "<STR_LIT>" ) : <EOL> posList = nbt . TAG_List ( [ nbt . TAG_Double ( p ) for p in ( x , y - <NUM_LIT> , z ) ] ) <EOL> playerTag = self . getPlayerTag ( player ) <EOL> playerTag [ "<STR_LIT>" ] = posList <EOL> def getPlayerPosition ( self , player = "<STR_LIT>" ) : <EOL> playerTag = self . getPlayerTag ( player ) <EOL> posList = playerTag [ "<STR_LIT>" ] <EOL> x , y , z = map ( lambda x : x . value , posList ) <EOL> return x , y + <NUM_LIT> , z <EOL> def setPlayerOrientation ( self , yp , player = "<STR_LIT>" ) : <EOL> self . getPlayerTag ( player ) [ "<STR_LIT>" ] = nbt . TAG_List ( [ nbt . TAG_Float ( p ) for p in yp ] ) <EOL> def getPlayerOrientation ( self , player = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> yp = map ( lambda x : x . value , self . getPlayerTag ( player ) [ "<STR_LIT>" ] ) <EOL> y , p = yp <EOL> if p == <NUM_LIT:0> : <EOL> p = <NUM_LIT> <EOL> if p == <NUM_LIT> : <EOL> p -= <NUM_LIT> <EOL> yp = y , p <EOL> return array ( yp ) <EOL> def setPlayerAbilities ( self , gametype , player = "<STR_LIT>" ) : <EOL> playerTag = self . getPlayerTag ( player ) <EOL> if not '<STR_LIT>' in playerTag : <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Compound ( ) <EOL> if gametype == <NUM_LIT:1> : <EOL> playerTag [ '<STR_LIT>' ] [ '<STR_LIT>' ] = nbt . TAG_Byte ( <NUM_LIT:1> ) <EOL> playerTag [ '<STR_LIT>' ] [ '<STR_LIT>' ] = nbt . TAG_Byte ( <NUM_LIT:1> ) <EOL> playerTag [ '<STR_LIT>' ] [ '<STR_LIT>' ] = nbt . TAG_Byte ( <NUM_LIT:1> ) <EOL> else : <EOL> playerTag [ '<STR_LIT>' ] [ '<STR_LIT>' ] = nbt . TAG_Byte ( <NUM_LIT:0> ) <EOL> playerTag [ '<STR_LIT>' ] [ '<STR_LIT>' ] = nbt . TAG_Byte ( <NUM_LIT:0> ) <EOL> playerTag [ '<STR_LIT>' ] [ '<STR_LIT>' ] = nbt . TAG_Byte ( <NUM_LIT:0> ) <EOL> playerTag [ '<STR_LIT>' ] [ '<STR_LIT>' ] = nbt . TAG_Byte ( <NUM_LIT:0> ) <EOL> def setPlayerGameType ( self , gametype , player = "<STR_LIT>" ) : <EOL> playerTag = self . getPlayerTag ( player ) <EOL> if player == "<STR_LIT>" : <EOL> self . GameType = gametype <EOL> self . setPlayerAbilities ( gametype , player ) <EOL> else : <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Int ( gametype ) <EOL> self . setPlayerAbilities ( gametype , player ) <EOL> def getPlayerGameType ( self , player = "<STR_LIT>" ) : <EOL> if player == "<STR_LIT>" : <EOL> return self . GameType <EOL> else : <EOL> playerTag = self . getPlayerTag ( player ) <EOL> return playerTag [ "<STR_LIT>" ] . value <EOL> def createPlayer ( self , playerName ) : <EOL> if playerName == "<STR_LIT>" : <EOL> playerTag = self . root_tag [ "<STR_LIT>" ] . setdefault ( playerName , nbt . TAG_Compound ( ) ) <EOL> else : <EOL> playerTag = nbt . TAG_Compound ( ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Short ( <NUM_LIT> ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Short ( <NUM_LIT:0> ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Short ( <NUM_LIT:0> ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Short ( - <NUM_LIT:20> ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Short ( <NUM_LIT:20> ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Short ( <NUM_LIT:0> ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Int ( <NUM_LIT:0> ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Float ( <NUM_LIT:0> ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_Byte ( <NUM_LIT:0> ) <EOL> playerTag [ "<STR_LIT>" ] = nbt . TAG_List ( ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_List ( [ nbt . TAG_Double ( <NUM_LIT:0> ) for i in range ( <NUM_LIT:3> ) ] ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_List ( [ nbt . TAG_Double ( [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT:0.5> ] [ i ] ) for i in range ( <NUM_LIT:3> ) ] ) <EOL> playerTag [ '<STR_LIT>' ] = nbt . TAG_List ( [ nbt . TAG_Float ( <NUM_LIT:0> ) , nbt . TAG_Float ( <NUM_LIT:0> ) ] ) <EOL> if playerName != "<STR_LIT>" : <EOL> if self . readonly : <EOL> raise IOError , "<STR_LIT>" <EOL> self . checkSessionLock ( ) <EOL> playerTag . save ( self . getPlayerPath ( playerName ) ) <EOL> class MCAlphaDimension ( MCInfdevOldLevel ) : <EOL> def __init__ ( self , parentWorld , dimNo , create = False ) : <EOL> filename = parentWorld . worldFolder . getFolderPath ( "<STR_LIT>" + str ( int ( dimNo ) ) ) <EOL> self . parentWorld = parentWorld <EOL> MCInfdevOldLevel . __init__ ( self , filename , create ) <EOL> self . dimNo = dimNo <EOL> self . filename = parentWorld . filename <EOL> self . players = self . parentWorld . players <EOL> self . playersFolder = self . parentWorld . playersFolder <EOL> self . playerTagCache = self . parentWorld . playerTagCache <EOL> @ property <EOL> def root_tag ( self ) : <EOL> return self . parentWorld . root_tag <EOL> def __str__ ( self ) : <EOL> return u"<STR_LIT>" . format ( self . parentWorld , self . dimNo ) <EOL> def loadLevelDat ( self , create = False , random_seed = None , last_played = None ) : <EOL> pass <EOL> def preloadDimensions ( self ) : <EOL> pass <EOL> def _create ( self , * args , ** kw ) : <EOL> pass <EOL> def acquireSessionLock ( self ) : <EOL> pass <EOL> def checkSessionLock ( self ) : <EOL> self . parentWorld . checkSessionLock ( ) <EOL> dimensionNames = { - <NUM_LIT:1> : "<STR_LIT>" , <NUM_LIT:1> : "<STR_LIT>" } <EOL> @ property <EOL> def displayName ( self ) : <EOL> return u"<STR_LIT>" . format ( self . parentWorld . displayName , <EOL> self . dimensionNames . get ( self . dimNo , "<STR_LIT>" % self . dimNo ) ) <EOL> def saveInPlace ( self , saveSelf = False ) : <EOL> """<STR_LIT>""" <EOL> if saveSelf : <EOL> MCInfdevOldLevel . saveInPlace ( self ) <EOL> else : <EOL> self . parentWorld . saveInPlace ( ) </s>
