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 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. 3
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