Exemple #1
0
    def readChunkCompressed(self, cx, cz):
        """
        Read a chunk and return its compression type and the compressed data as a (data, fmt) tuple
        """
        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 file(self.path, "rb") as f:
            f.seek(sectorStart * self.SECTOR_BYTES)
            data = f.read(numSectors * self.SECTOR_BYTES)
        if len(data) < 5:
            raise RegionFormatError(
                "Chunk %s data is only %d bytes long (expected 5)" %
                ((cx, cz), len(data)))

        # region_debug("REGION LOAD {0},{1} sector {2}".format(cx, cz, sectorStart))

        length = struct.unpack_from(">I", data)[0]
        fmt = struct.unpack_from("B", data, 4)[0]
        data = data[5:length + 5]
        return data, fmt
Exemple #2
0
    def readChunk(self, cx, cz, dimName, create=False):
        """
        Creates a FakeChunkData object representing the chunk at the given
        position. Subclasses may choose to override
        fakeBlocksForChunk and fakeDataForChunk to provide block and blockdata arrays.
        They may instead override getChunk and return a ChunkBase subclass.

        By default, returns a chunk whose ``Blocks`` is made from slices of self.Blocks (and
        ``Data`` from self.Data if present)
        """
        if not self.bounds.containsChunk(cx, cz):
            raise ChunkNotPresent((cx, cz))
        chunk = self.ChunkDataClass()
        chunk.dimension = self
        chunk.cx = cx
        chunk.cz = cz
        chunk.dimName = dimName

        chunk.Blocks = self.fakeBlocksForChunk(cx, cz)

        chunk.Data = self.fakeDataForChunk(cx, cz)

        whiteLight = zeros_like(chunk.Blocks)
        whiteLight[:] = 15

        chunk.BlockLight = whiteLight
        chunk.SkyLight = whiteLight

        chunk.Entities, chunk.TileEntities = self.fakeEntitiesForChunk(cx, cz)

        chunk.rootTag = nbt.TAG_Compound()

        return chunk
Exemple #3
0
    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
Exemple #4
0
    def readChunkBytes(self, cx, cz, dimName):
        if self.invalid:
            raise RuntimeError("Accessing invalid node: %r" % self)
        node = self
        while node:
            # Ask RevisionHistory for most recent node containing this chunk?
            if (cx, cz, dimName) in node.deadChunks:
                raise ChunkNotPresent((cx, cz), "Chunk was deleted")
            if node.worldFolder.containsChunk(cx, cz, dimName):
                data = node.worldFolder.readChunkBytes(cx, cz, dimName)
                return data
            if node is self.history.rootNode:
                break

            node = node.parentNode

        raise ChunkNotPresent((cx, cz))
Exemple #5
0
    def getChunk(self, cx, cz, create=False):
        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
Exemple #6
0
 def readChunkBytes(self, cx, cz, dimName):
     if not self.containsChunk(cx, cz, dimName):
         raise ChunkNotPresent((cx, cz))
     return self.getRegionForChunk(cx, cz, dimName).readChunkBytes(cx, cz)