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
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)
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
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
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
def biomes(self, value: Union[Biomes, Dict[int, numpy.ndarray]]): self._biomes = Biomes(value)
def biomes(self) -> Biomes: if self._biomes is None: self._biomes = Biomes() return self._biomes
def biomes(self) -> Biomes: if self._biomes is None: self._biomes = Biomes(self, numpy.zeros((16, 16), dtype=numpy.uint32)) return self._biomes