amulet_nbt.CompoundTag
class
- class amulet_nbt.CompoundTag[source]
Bases:
CyCompoundTag
,MutableMapping
- get_byte(key, default=None)[source]
Get the tag stored in key if it is a ByteTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The ByteTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a ByteTag
- get_byte_array(key, default=None)[source]
Get the tag stored in key if it is a ByteArrayTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The ByteArrayTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a ByteArrayTag
- get_compound(key, default=None)[source]
Get the tag stored in key if it is a CyCompoundTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The CyCompoundTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a CyCompoundTag
- get_double(key, default=None)[source]
Get the tag stored in key if it is a DoubleTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The DoubleTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a DoubleTag
- get_float(key, default=None)[source]
Get the tag stored in key if it is a FloatTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The FloatTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a FloatTag
- get_int(key, default=None)[source]
Get the tag stored in key if it is a IntTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The IntTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a IntTag
- get_int_array(key, default=None)[source]
Get the tag stored in key if it is a IntArrayTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The IntArrayTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a IntArrayTag
- get_list(key, default=None)[source]
Get the tag stored in key if it is a CyListTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The CyListTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a CyListTag
- get_long(key, default=None)[source]
Get the tag stored in key if it is a LongTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The LongTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a LongTag
- get_long_array(key, default=None)[source]
Get the tag stored in key if it is a LongArrayTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The LongArrayTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a LongArrayTag
- get_short(key, default=None)[source]
Get the tag stored in key if it is a ShortTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The ShortTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a ShortTag
- get_string(key, default=None)[source]
Get the tag stored in key if it is a StringTag.
- Parameters:
key – The key to get
default – The value to return if the key does not exist or the type is wrong. If not defined errors are raised.
- Returns:
The StringTag.
- Raises:
KeyError if the key does not exist
- Raises:
TypeError if the stored type is not a StringTag
- pop(k[, d]) v, remove specified key and return the corresponding value. [source]
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair [source]
as a 2-tuple; but raise KeyError if D is empty.
- 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_dict[source]
A python dictionary 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.
- 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:
- Return type:
- Returns:
The binary NBT representation of the class.
- setdefault_byte(key, default=None)[source]
Populate key if not defined or value is not ByteTag. Return the value stored.
If default is a ByteTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The ByteTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_byte_array(key, default=None)[source]
Populate key if not defined or value is not ByteArrayTag. Return the value stored.
If default is a ByteArrayTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The ByteArrayTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_compound(key, default=None)[source]
Populate key if not defined or value is not CyCompoundTag. Return the value stored.
If default is a CyCompoundTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The CyCompoundTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_double(key, default=None)[source]
Populate key if not defined or value is not DoubleTag. Return the value stored.
If default is a DoubleTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The DoubleTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_float(key, default=None)[source]
Populate key if not defined or value is not FloatTag. Return the value stored.
If default is a FloatTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The FloatTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_int(key, default=None)[source]
Populate key if not defined or value is not IntTag. Return the value stored.
If default is a IntTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The IntTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_int_array(key, default=None)[source]
Populate key if not defined or value is not IntArrayTag. Return the value stored.
If default is a IntArrayTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The IntArrayTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_list(key, default=None)[source]
Populate key if not defined or value is not CyListTag. Return the value stored.
If default is a CyListTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The CyListTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_long(key, default=None)[source]
Populate key if not defined or value is not LongTag. Return the value stored.
If default is a LongTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The LongTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_long_array(key, default=None)[source]
Populate key if not defined or value is not LongArrayTag. Return the value stored.
If default is a LongArrayTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The LongArrayTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_short(key, default=None)[source]
Populate key if not defined or value is not ShortTag. Return the value stored.
If default is a ShortTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The ShortTag stored in key :raises: TypeError if the input types are incorrect
- setdefault_string(key, default=None)[source]
Populate key if not defined or value is not StringTag. Return the value stored.
If default is a StringTag then it will be stored under key else a default instance will be created. :type key: :param key: The key to populate and get :type default: :param default: The default value to use :return: The StringTag stored in key :raises: TypeError if the input types are incorrect
- to_nbt(*, compressed=True, little_endian=False, string_encoder=<built-in function encode_modified_utf8>, name='')[source]
Get the data in binary NBT format.
- 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.
- update([E, ]**F) None. Update D from mapping/iterable E and F. [source]
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v