amulet_nbt.NamedTag class

class amulet_nbt.NamedTag[source]
__init__(*args, **kwargs)[source]
byte[source]

Get the tag if it is a ByteTag.

Returns:

The ByteTag.

Raises:

TypeError if the stored type is not a ByteTag

byte_array[source]

Get the tag if it is a ByteArrayTag.

Returns:

The ByteArrayTag.

Raises:

TypeError if the stored type is not a ByteArrayTag

compound[source]

Get the tag if it is a CyCompoundTag.

Returns:

The CyCompoundTag.

Raises:

TypeError if the stored type is not a CyCompoundTag

double[source]

Get the tag if it is a DoubleTag.

Returns:

The DoubleTag.

Raises:

TypeError if the stored type is not a DoubleTag

float[source]

Get the tag if it is a FloatTag.

Returns:

The FloatTag.

Raises:

TypeError if the stored type is not a FloatTag

get(k, default=None)[source]

Depreciated. Do not use.

Return type:

AnyNBT

int[source]

Get the tag if it is a IntTag.

Returns:

The IntTag.

Raises:

TypeError if the stored type is not a IntTag

int_array[source]

Get the tag if it is a IntArrayTag.

Returns:

The IntArrayTag.

Raises:

TypeError if the stored type is not a IntArrayTag

items()[source]

Depreciated. Do not use.

keys()[source]

Depreciated. Do not use.

list[source]

Get the tag if it is a CyListTag.

Returns:

The CyListTag.

Raises:

TypeError if the stored type is not a CyListTag

long[source]

Get the tag if it is a LongTag.

Returns:

The LongTag.

Raises:

TypeError if the stored type is not a LongTag

long_array[source]

Get the tag if it is a LongArrayTag.

Returns:

The LongArrayTag.

Raises:

TypeError if the stored type is not a LongArrayTag

name[source]
pop(k, default=None)[source]

Depreciated. Do not use.

Return type:

AnyNBT

save_to(filepath_or_buffer=None, *args, compressed=True, little_endian=False, string_encoder=<built-in function encode_modified_utf8>)[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.

Return type:

bytes

Returns:

The binary NBT representation of the class.

short[source]

Get the tag if it is a ShortTag.

Returns:

The ShortTag.

Raises:

TypeError if the stored type is not a ShortTag

string[source]

Get the tag if it is a StringTag.

Returns:

The StringTag.

Raises:

TypeError if the stored type is not a StringTag

tag[source]
to_nbt(*, compressed=True, little_endian=False, string_encoder=<built-in function encode_modified_utf8>)[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.

Return type:

bytes

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 get the tag. Depreciated. Use tag or get_{type} instead.

values()[source]

Depreciated. Do not use.