def test_list_tag_data_with_compound_tags(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = { 'tag_name': 'ActiveEffects', 'type': 'List', 'value': [ { 'tag_name': '', 'type': 0xA, 'value': [ { 'tag_name': 'Ambient', 'type': 'Byte', 'value': 0 }, { 'tag_name': 'ShowIcon', 'type': 'Byte', 'value': 1 }, { 'tag_name': 'ShowParticles', 'type': 'Byte', 'value': 0 }, { 'tag_name': 'Duration', 'type': 'Int', 'value': 200 }, { 'tag_name': 'Id', 'type': 'Byte', 'value': 13 }, { 'tag_name': 'Amplifier', 'type': 'Byte', 'value': 0 } ] } ] } nbt_data = nbt.write_tag(buf, data) output = '09 00 0D 41 63 74 69 76 65 45 66 66 65 63 74 73 ' # compound output += '0A 00 00 00 01 01 00 07 41 6D 62 69 65 6E 74 00 ' # ambient output += '01 00 08 53 68 6F 77 49 63 6F 6E 01 ' # showicon output += '01 00 0D 53 68 6F 77 50 61 72 74 69 63 6C 65 73 00 ' # showpart output += '03 00 08 44 75 72 61 74 69 6F 6E 00 00 00 C8 ' # duration output += '01 00 02 49 64 0D ' # id output += '01 00 09 41 6D 70 6C 69 66 69 65 72 00 00' # amp + end tag expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "list with compound data is not equal"
def test_tag_data_to_int(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = {'tag_name': 'zCenter', 'value': -3200, 'type': 'Int'} nbt_data = nbt.write_tag(buf, data) output = '03 00 07 7A 43 65 6E 74 65 72 FF FF F3 80' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "int data is not equal"
def test_tag_data_to_bytes(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = {'tag_name': 'unlimitedTracking', 'value': 0, 'type': 'Byte'} nbt_data = nbt.write_tag(buf, data) output = '01 00 11 75 6E 6C 69 6D 69 74 65 64 54 72 61 63 6B 69 6E 67 00' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "byte data is not equal"
def test_tag_data_to_double(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = {'tag_name': 'BorderCenterZ', 'value': 0, 'type': 'Double'} nbt_data = nbt.write_tag(buf, data) output = '06 00 0D 42 6F 72 64 65 72 43 65 6E 74 65 72 5A 00 00 00 00 00 00 00 00' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "double data is not equal"
def test_scalar_type_tag_data_to_list(): bio = io.BytesIO() buf = io.BufferedWriter(bio) rots = [-128.2454833984375, 16.366594314575195] # list of type float with 2 items list_data = {'value': rots, 'type': 'Float'} data = {'tag_name': 'Rotation', 'value': list_data, 'type': 'List'} nbt_data = nbt.write_tag(buf, data) output = '09 00 08 52 6F 74 61 74 69 6F 6E 05 00 00 00 02 C3 00 3E D8 41 82 EE C9' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "list data is not equal"
def test_tag_data_to_string(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = { 'tag_name': 'WanderingTraderId', 'value': '26f2a721-4d4e-4595-a1ee-0b259d814d20', 'type': 'String' } nbt_data = nbt.write_tag(buf, data) output = '08 00 11 57 61 6E 64 65 72 69 6E 67 54 72 61 64 65 72 49 64 00 24 32 36 66 32 61 37 32 31 2D 34 64 34 65 2D 34 35 39 35 2D 61 31 65 65 2D 30 62 32 35 39 64 38 31 34 64 32 30' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "string data is not equal"
def test_tag_data_to_byte_array(): bio = io.BytesIO() buf = io.BufferedWriter(bio) colors = {'size': 2, 'size_bytes': 1, 'value': [0x01, 0x55]} data = {'tag_name': 'colors', 'value': colors, 'type': 'Byte_Array'} nbt_data = nbt.write_tag(buf, data) output = '07 00 06 63 6F 6C 6F 72 73 00 00 00 02 01 55' expected_output = bytes.fromhex(output) print('expected {} got {}'.format(expected_output, nbt_data)) assert nbt_data == expected_output, "byte array data is not equal"
def test_tag_data_to_long(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = { 'tag_name': 'UUIDLeast', 'value': -8713279898927853564, 'type': 'Long' } nbt_data = nbt.write_tag(buf, data) output = '04 00 09 55 55 49 44 4C 65 61 73 74 87 14 36 18 CB DA 90 04' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "short data is not equal"
def test_tag_data_to_short(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = { 'tag_name': 'Fire', 'value': -20, 'type': 'Short' } nbt_data = nbt.write_tag(buf, data) output = '02 00 04 46 69 72 65 FF EC' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "short data is not equal"
def test_tag_data_to_float(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = { 'tag_name': 'walkSpeed', 'value': 0.10000000149011612, 'type': 'Float' } nbt_data = nbt.write_tag(buf, data) output = '05 00 09 77 61 6C 6B 53 70 65 65 64 3D CC CC CD' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "float data is not equal"
def test_multiple_tag_data_to_compound(): bio = io.BytesIO() buf = io.BufferedWriter(bio) data = { 'tag_name': '', 'type': 'Compound', 'value': [ { 'tag_name': 'data', 'type': 'Compound', 'value': [ { 'tag_name': 'Raids', 'type': 'List', 'value': {'type': 'End', 'value': []} }, { 'tag_name': 'NextAvailableID', 'type': 'Int', 'value': 8 }, { 'tag_name': 'Tick', 'type': 'Int', 'value': 25474854 } ] }, { 'tag_name': 'DataVersion', 'type': 'Int', 'value': 2229 } ] } nbt_data = nbt.write_tag(buf, data) output = '0a 00 00 0a 00 04 64 61 74 61 09 00 05 52 61 69 ' output += '64 73 00 00 00 00 00 03 00 0f 4e 65 78 74 41 76 ' output += '61 69 6c 61 62 6c 65 49 44 00 00 00 08 03 00 04 ' output += '54 69 63 6b 01 84 b7 26 00 03 00 0b 44 61 74 61 ' output += '56 65 72 73 69 6f 6e 00 00 08 b5 00' expected_output = bytes.fromhex(output) assert nbt_data == expected_output, "compound data is not equal"
def test_tag_data_to_int_array(): bio = io.BytesIO() buf = io.BufferedWriter(bio) # 45: Lukewarm Ocean # 5: Taiga # 19: Taiga Hills biomes = {'size': 4, 'size_bytes': 4, 'value': [45, 45, 5, 19]} data = {'tag_name': 'Biomes', 'value': biomes, 'type': 'Int_Array'} nbt_data = nbt.write_tag(buf, data) output = '0B 00 06 42 69 6F 6D 65 73 00 00 00 04 00 00 00 2D 00 00 00 2D 00 00 00 05 00 00 00 13' expected_output = bytes.fromhex(output) print('exp {}\ngot {}'.format(expected_output, nbt_data)) assert nbt_data == expected_output, "int array data is not equal"
def test_tag_data_to_long_array(): bio = io.BytesIO() buf = io.BufferedWriter(bio) block_states = {'size': 3, 'size_bytes': 8, 'value': [1229782938247303441, 1229782938247303441, 1229782938532516113]} data = { 'tag_name': 'BlockStates', 'value': block_states, 'type': 'Long_Array' } nbt_data = nbt.write_tag(buf, data) output = '0C 00 0B 42 6C 6F 63 6B 53 74 61 74 65 73 00 00 00 03 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 22 11 11 11' expected_output = bytes.fromhex(output) print('expected {} got {}'.format(expected_output, nbt_data)) assert nbt_data == expected_output, "long array data is not equal"