def test_break_block(self): chunk = decode_chunk(self.data) base = Vector3(0, 0, 0) height = chunk.get_height(base.x, base.z) for y in range(height): self.assertNotEqual(BlockType.AIR, chunk.get_block(base.copy(y=y)).type) for y in range(height, 127): self.assertEqual(BlockType.AIR, chunk.get_block(base.copy(y=y)).type) chunk.set_block(base.copy(y=height - 1), Block.create(BlockType.AIR, 0)) expected_height = height - 1 height = chunk.get_height(base.x, base.z) self.assertEqual(expected_height, height) self.assertNotEqual(BlockType.AIR, chunk.get_block(base.copy(y=height - 1)).type) for y in range(height, 127): self.assertEqual(BlockType.AIR, chunk.get_block(base.copy(y=y)).type) chunk.set_block(base.copy(y=height - 2), Block.create(BlockType.AIR, 0)) expected_height = height height = chunk.get_height(base.x, base.z) self.assertEqual(expected_height, height) self.assertNotEqual(BlockType.AIR, chunk.get_block(base.copy(y=height - 1)).type) for y in range(height, 127): self.assertEqual(BlockType.AIR, chunk.get_block(base.copy(y=y)).type)
def _load_version4(self, position: ChunkPosition) -> Chunk: sub_chunks = [] for i in range(ChunkGeometry.SHAPE.y // ChunkGeometry.Sub.SHAPE.y): key = self._key_codec.encode(position.x, position.z, _Tag.SUB_CHUNK, i) try: data = self._db.Get(key) sub_chunks.append(data) except KeyError: break data = bytearray() data.append(len(sub_chunks)) for sub_chunk in sub_chunks: data += sub_chunk key = self._key_codec.encode(position.x, position.z, _Tag.DATA_2D) d = self._db.Get(key) data += d data.append(0) # TODO set data data.append(0) # TODO set data return decode_chunk(bytes(data))
def load_chunk(self, position: ChunkPosition) -> Optional[Chunk]: param = (position.x, position.z) row = self._connection.execute( 'SELECT data FROM chunk WHERE x=? AND z=?', param).fetchone() return decode_chunk(row[0]) if row else None
def load_chunk(self, position: ChunkPosition) -> Optional[Chunk]: param = ":".join([str(position.x), str(position.z)]) if param in self._data["chunk"]: return decode_chunk(binascii.unhexlify(self._data["chunk"][param]))
def test_chunk_01(self): chunk = decode_chunk(self.data) data = encode_chunk(chunk) self.assertEqual(self.data, data)
def _process_full_chunk_data(self, packet: GamePacket, addr: Address) -> None: self._latest_chunk = ChunkInfo(packet.position, decode_chunk(packet.data))
def generate_chunk() -> Iterator[Chunk]: for packet in packet_list: if packet.__class__.__name__ == 'PacketFullChunkData': yield decode_chunk(packet.data)
def _load_version2(self, position: ChunkPosition) -> Chunk: key = self._key_codec.encode(position.x, position.z, _Tag.LEGACY_TERRAIN) data = self._db.Get(key) return decode_chunk(data, is_legacy=True)