def _readChunk(self, cx, cz): cx &= 0x1f cz &= 0x1f offset = self.getOffset(cx, cz) if offset == 0: raise ChunkNotPresent((cx, cz)) sectorStart = offset >> 8 numSectors = offset & 0xff if numSectors == 0: raise ChunkNotPresent((cx, cz)) if sectorStart + numSectors > len(self.freeSectors): raise ChunkNotPresent((cx, cz)) with self.file as f: f.seek(sectorStart * self.SECTOR_BYTES) data = f.read(numSectors * self.SECTOR_BYTES) if len(data) < 5: raise RegionMalformed("Chunk data is only %d bytes long (expected 5)" % len(data)) # log.debug("REGION LOAD {0},{1} sector {2}".format(cx, cz, sectorStart)) length = struct.unpack_from(">I", data)[0] format = struct.unpack_from("B", data, 4)[0] data = data[5:length + 5] return data, format
def loadChunk(self, cx, cz, world): data = self._readChunk(cx, cz) if data is None: raise ChunkNotPresent((cx, cz, self)) chunk = PocketChunk(cx, cz, data[4:], world) return chunk
def copyChunkAtPosition(self, tempWorld, level, cx, cz): if level.containsChunk(cx, cz): return try: tempChunkBytes = tempWorld._getChunkBytes(cx, cz) except ChunkNotPresent, e: raise ChunkNotPresent( "While generating a world in {0} using server {1} ({2!r})". format(tempWorld, self.serverJarFile, e), sys.exc_info()[2])
def getChunk(self, cx, cz): for p in cx, cz: if not 0 <= p <= 31: raise ChunkNotPresent((cx, cz, self)) c = self._loadedChunks.get((cx, cz)) if c is None: c = self.chunkFile.loadChunk(cx, cz, self) self._loadedChunks[cx, cz] = c return c
def copyChunkAtPosition(self, tempWorld, level, cx, cz): if level.containsChunk(cx, cz): return try: tempChunkBytes = tempWorld._getChunkBytes(cx, cz) except ChunkNotPresent as e: raise ChunkNotPresent("While generating a world in {0} using server {1} ({2!r})".format(tempWorld, self.serverJarFile, e)).with_traceback(sys.exc_info()[2]) level.worldFolder.saveChunk(cx, cz, tempChunkBytes) level._allChunks = None
def loadChunk(self, cx, cz, world): """ :param cx, cz: int Coordinates of the chunk :param world: PocketLeveldbWorld :return: PocketLeveldbChunk """ data = self._readChunk(cx, cz) if data is None: raise ChunkNotPresent((cx, cz, self)) chunk = PocketLeveldbChunk(cx, cz, world, data) return chunk
def copyChunkAtPosition(self, tempWorld, level, cx, cz): if level.containsChunk(cx, cz): return try: tempChunkBytes = tempWorld._getChunkBytes(cx, cz) except ChunkNotPresent as e: raise ChunkNotPresent("While generating a world in {0} using server {1} ({2!r})".format(tempWorld, self.serverJarFile, e), sys.exc_info()[ 2]) if isinstance(level, PocketLeveldbWorld): level.saveGeneratedChunk(cx, cz, tempChunkBytes) else: level.worldFolder.saveChunk(cx, cz, tempChunkBytes) level._allChunks = None