def test_deserializing(args): raw_tag = InputStream(bytearray([clz.clazz_id, 0, 4] + \ list(b'Test') + \ test_bin)) parsed_tag = parse_nbt(raw_tag) expected_tag = clz(test_val, tag_name='Test') assert parsed_tag == expected_tag, f'Tag {clz.clazz_name}'
def test_deserializing(args): raw_tag = InputStream(bytearray([10, 0, 4] + \ list(b'Test') + \ [1, 0, 3,] + list(b'dp1') + [25] +\ [5, 0, 3,] + list(b'dp2') + [63, 192, 0, 0] +\ [9, 0, 3,] + list(b'dp3') + [1, 0, 0, 0, 1] + [35] +\ [10, 0, 3,] + list(b'dp4') +\ [7, 0, 6,] + list(b'sub_dp') + [0, 0, 0, 2, 10, 20] + [0] +\ [0])) parsed_tag = parse_nbt(raw_tag) tag = CompoundTag(tag_name='Test', children=[ ByteTag(25, tag_name='dp1'), FloatTag(1.5, tag_name='dp2'), ListTag(ByteTag.clazz_id, tag_name='dp3', children=[ByteTag(35)]), CompoundTag(tag_name='dp4', children=[ ByteArrayTag(tag_name='sub_dp', children=[ ByteTag(10), ByteTag(20) ]) ]) ]) assert parsed_tag == tag, 'Tag ListTag with ListTag elements'
def test_deserializing(args): raw_tag = InputStream(bytearray([8, 0, 4] + \ list(b'Test') + \ [0,len('Hello World')] +\ list(b'Hello World'))) parsed_tag = parse_nbt(raw_tag) tag = StringTag('Hello World', tag_name='Test') assert parsed_tag == tag, 'Tag StringTag'
def test_deserializing(args): raw_tag = InputStream(bytearray([clz.clazz_id, 0, 4] + \ list(b'Test') + \ [0,0,0,len(test_vals)] +\ [b for sublist in test_bins for b in sublist])) parsed_tag = parse_nbt(raw_tag) expected_tag = clz( 'Test', children=[clz.clazz_sub_type(v) for v in test_vals]) assert parsed_tag == expected_tag, f'Tag {clz.clazz_name}'
def _load_binary_chunk_at(self, region_file, offset): region_file.seek(offset) datalen = int.from_bytes(region_file.read(4), byteorder='big', signed=False) compr = region_file.read(1) decompressed = zlib.decompress(region_file.read(datalen)) data = nbt.parse_nbt(stream.InputStream(decompressed)) chunk_pos = (data.get('Level').get('xPos').get(), data.get('Level').get('zPos').get()) chunk = Chunk(chunk_pos[0], chunk_pos[1], data) return chunk
def __init__(self, world_path: str, username: str = "", uuid: str = ""): if uuid == "": uuid = self._username_to_uuid(username) uuid_fn = self._uuid_to_filename(uuid) player_path = os.path.join(world_path, "playerdata", uuid_fn + ".dat") with gzip.open(player_path, mode='rb') as player_file: in_stream = stream.InputStream(player_file.read()) p_data = nbt.parse_nbt(in_stream) self.pos = [c.get() for c in p_data.get("Pos").children] self.rot = [c.get() for c in p_data.get("Rotation").children] self.dim = p_data.get("Dimension").get()
def test_deserializing_simple_data(args): raw_tag = InputStream(bytearray([9, 0, 4] + \ list(b'Test') + \ [5, 0, 0, 0, 2] +\ [63, 192, 0, 0, 65, 50, 102, 102])) parsed_tag = parse_nbt(raw_tag) tag = ListTag( FloatTag.clazz_id, tag_name='Test', children=[ FloatTag(1.5), FloatTag(11.149999618530273) # float pack error ]) assert parsed_tag == tag, 'Tag ListTag with FloatTag elements'
def test_deserializing_list_data(args): raw_tag = InputStream(bytearray([9, 0, 4] + \ list(b'Test') + \ [9, 0, 0, 0, 2] +\ [1, 0, 0, 0, 2] +\ [25, 31] +\ [5, 0, 0, 0, 1] +\ [63, 192, 0, 0])) parsed_tag = parse_nbt(raw_tag) tag = ListTag(ListTag.clazz_id, tag_name='Test', children=[ ListTag(ByteTag.clazz_id, children=[ByteTag(25), ByteTag(31)]), ListTag(FloatTag.clazz_id, children=[FloatTag(1.5)]) ]) assert parsed_tag == tag, 'Tag ListTag with ListTag elements'
def test_deserializing_compund_data(args): raw_tag = InputStream(bytearray([9, 0, 4] + \ list(b'Test') + \ [10, 0, 0, 0, 2] +\ [1, 0, 3,] + list(b'dp1') + [25] +\ [1, 0, 3,] + list(b'dp2') + [31, 0] +\ [1, 0, 3,] + list(b'dp3') + [25] +\ [1, 0, 3,] + list(b'dp4') + [31, 0])) parsed_tag = parse_nbt(raw_tag) tag = ListTag(CompoundTag.clazz_id, tag_name='Test', children=[ CompoundTag(children=[ ByteTag(25, tag_name='dp1'), ByteTag(31, tag_name='dp2') ]), CompoundTag(children=[ ByteTag(25, tag_name='dp3'), ByteTag(31, tag_name='dp4') ]) ]) assert parsed_tag == tag, 'Tag ListTag with ListTag elements'