amulet_nbt.ListTag class

class amulet_nbt.ListTag[source]

Bases: CyListTag, MutableSequence

__init__(*args, **kwargs)[source]
append(value)[source]

S.append(value) – append value to the end of the sequence

clear() None -- remove all items from S[source]
copy()[source]

Return a shallow copy of the class

count(value) integer -- return number of occurrences of value[source]
classmethod create(value=(), list_data_type=1)[source]
Return type:

ListTag

extend(values)[source]

S.extend(iterable) – extend sequence by appending elements from the iterable

get_byte(index)[source]

Get the tag at index if it is a ByteTag.

Parameters:

index – The index to get

Returns:

The ByteTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a ByteTag

get_byte_array(index)[source]

Get the tag at index if it is a ByteArrayTag.

Parameters:

index – The index to get

Returns:

The ByteArrayTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a ByteArrayTag

get_compound(index)[source]

Get the tag at index if it is a CyCompoundTag.

Parameters:

index – The index to get

Returns:

The CyCompoundTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a CyCompoundTag

get_double(index)[source]

Get the tag at index if it is a DoubleTag.

Parameters:

index – The index to get

Returns:

The DoubleTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a DoubleTag

get_float(index)[source]

Get the tag at index if it is a FloatTag.

Parameters:

index – The index to get

Returns:

The FloatTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a FloatTag

get_int(index)[source]

Get the tag at index if it is a IntTag.

Parameters:

index – The index to get

Returns:

The IntTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a IntTag

get_int_array(index)[source]

Get the tag at index if it is a IntArrayTag.

Parameters:

index – The index to get

Returns:

The IntArrayTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a IntArrayTag

get_list(index)[source]

Get the tag at index if it is a CyListTag.

Parameters:

index – The index to get

Returns:

The CyListTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a CyListTag

get_long(index)[source]

Get the tag at index if it is a LongTag.

Parameters:

index – The index to get

Returns:

The LongTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a LongTag

get_long_array(index)[source]

Get the tag at index if it is a LongArrayTag.

Parameters:

index – The index to get

Returns:

The LongArrayTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a LongArrayTag

get_short(index)[source]

Get the tag at index if it is a ShortTag.

Parameters:

index – The index to get

Returns:

The ShortTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a ShortTag

get_string(index)[source]

Get the tag at index if it is a StringTag.

Parameters:

index – The index to get

Returns:

The StringTag.

Raises:

IndexError if the index is outside the list.

Raises:

TypeError if the stored type is not a StringTag

index(value[, start[, stop]]) integer -- return first index of value.[source]

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

insert(index, value)[source]

S.insert(index, value) – insert value before index

list_data_type[source]
pop([index]) item -- remove and return item at index (default last).[source]

Raise IndexError if list is empty or index is out of range.

py_data[source]

A python representation of the class. Note that the return type is undefined and may change in the future. You would be better off using the py_{type} or np_array properties if you require a fixed type. This is here for convenience to get a python representation under the same property name.

py_list[source]

A python list representation of the class. The returned list is a shallow copy of the class, meaning changes will not mirror the instance. Use the public API to modify the internal data.

remove(value)[source]

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

reverse()[source]

S.reverse() – reverse IN PLACE

save_to(filepath_or_buffer=None, *, compressed=True, little_endian=False, string_encoder=<built-in function encode_modified_utf8>, name='')[source]

Convert the data to the binary NBT format. Optionally write to a file.

If filepath_or_buffer is a valid file path in string form the data will be written to that file.

If filepath_or_buffer is a file like object the bytes will be written to it using .write method.

Parameters:
  • filepath_or_buffer – A path or writeable object to write the data to.

  • compressed – Should the bytes be compressed with gzip.

  • little_endian – Should the bytes be saved in little endian format.

  • string_encoder (Callable[[str], bytes]) – A function to encode strings to bytes.

  • name – The root tag name.

Return type:

bytes

Returns:

The binary NBT representation of the class.

tag_id = 9[source]
to_nbt(*, compressed=True, little_endian=False, string_encoder=<built-in function encode_modified_utf8>, name='')[source]

Get the data in binary NBT format.

Parameters:
  • compressed – Should the bytes be compressed with gzip.

  • little_endian – Should the bytes be saved in little endian format.

  • string_encoder (Callable[[str], bytes]) – A function to encode strings to bytes.

  • name – The root tag name.

Returns:

The binary NBT representation of the class.

to_snbt(indent=None, indent_chr=None)[source]

Return the NBT data in Stringified NBT format.

Parameters:
  • indent – int, str or None. If int will indent with this many spaces. If string will indent with this string. If None will return on one line.

  • indent_chr – Depreciated. Use indent instead.

Returns:

Stringified NBT representation of the data.

value[source]

Legacy property to access the python data. Depreciated. Use py_data or typed py_{type} instead.