Esempio n. 1
0
    def unpickle(
        cls,
        pickled_bytes: bytes,
        block_palette: BlockManager,
        biome_palette: BiomeManager,
    ) -> Chunk:
        """
        Deserialise the pickled input and unpack the data into an instance of :class:`Chunk`

        :param pickled_bytes: The bytes returned from :func:`pickle`
        :param block_palette: The instance of :class:`BlockManager` associated with the level.
        :param biome_palette: The instance of :class:`BiomeManager` associated with the level.
        :return: An instance of :class:`Chunk` containing the unpickled data.
        """
        chunk_data = pickle.loads(pickled_bytes)
        self = cls(*chunk_data[:2])
        (
            self.blocks,
            biomes,
            self.entities,
            self.block_entities,
            self.status,
            self.misc,
        ) = chunk_data[3:]

        self._biomes = Biomes.from_raw(*biomes)

        self._changed_time = chunk_data[2]
        self._block_palette = block_palette
        self._biome_palette = biome_palette
        self.changed = False
        return self
Esempio n. 2
0
 def biomes(self, value: numpy.ndarray):
     if not numpy.array_equal(self._biomes, value):
         assert value.size in [
             0,
             256,
             1024,
         ], "Size of the Biome array must be 256 or 1024"
         numpy.issubdtype(
             value.dtype, numpy.integer
         ), "dtype must be an unsigned integer"
         self._biomes = Biomes(self, value)
Esempio n. 3
0
    def biomes(self) -> Biomes:
        """
        The biome array for the chunk.

        This is a custom class that stores numpy arrays. See the :class:`Biomes` documentation for more information.

        The values in the arrays are indexes into :attr:`biome_palette`.
        """
        if self._biomes is None:
            self._biomes = Biomes()
        return self._biomes
Esempio n. 4
0
    def unpickle(cls, file_path: str, block_palette: BlockManager,
                 biome_palette: BiomeManager) -> Chunk:
        chunk_data = pickle.loads(CacheDB.get(file_path.encode("utf-8")))
        self = cls(*chunk_data[:2])
        (
            self.blocks,
            biomes,
            self.entities,
            self.block_entities,
            self.status,
            self.misc,
        ) = chunk_data[3:]

        self._biomes = Biomes.from_raw(*biomes)

        self._changed_time = chunk_data[2]
        self._block_palette = block_palette
        self._biome_palette = biome_palette
        self.changed = False
        return self
Esempio n. 5
0
    def unpickle(cls, file_path: str, block_palette: BlockManager,
                 biome_palette: BiomeManager) -> Chunk:
        with gzip.open(file_path, "rb") as fp:
            chunk_data = pickle.load(fp)
        self = cls(*chunk_data[:2])
        (
            self.blocks,
            biomes,
            self.entities,
            self.block_entities,
            self.status,
            self.misc,
        ) = chunk_data[3:]

        self._biomes = Biomes.from_raw(*biomes)

        self._changed_time = chunk_data[2]
        self._block_palette = block_palette
        self._biome_palette = biome_palette
        self.changed = False
        return self
Esempio n. 6
0
 def biomes(self, value: Union[Biomes, Dict[int, numpy.ndarray]]):
     self._biomes = Biomes(value)
Esempio n. 7
0
 def biomes(self) -> Biomes:
     if self._biomes is None:
         self._biomes = Biomes()
     return self._biomes
Esempio n. 8
0
 def biomes(self) -> Biomes:
     if self._biomes is None:
         self._biomes = Biomes(self, numpy.zeros((16, 16), dtype=numpy.uint32))
     return self._biomes