NBT

Quarry implements the Named Binary Tag (NBT) format. The following tag types are available from the quarry.types.nbt module:

Class Value type
TagByte int
TagShort int
TagInt int
TagLong int
TagFloat float
TagDouble float
TagByteArray PackedArray with 8-bit sectors
TagIntArray PackedArray with 32-bit sectors
TagLongArray PackedArray with 64-bit sectors
TagString str (py3) or unicode (py2)
TagList list of tags.
TagCompound dict of names and tags.
TagRoot dict containing a single name and tag.

Note

Unlike some other NBT libraries, a tag’s name is stored by its parent - either a TagRoot or a TagCompound. A tag when considered alone is always nameless.

Tags

All tag types have the following attributes and methods:

Tag.__init__(value)

Creates a tag object from the given value.

classmethod Tag.from_bytes(bytes)

Creates a tag object from data at the beginning of the supplied byte string.

classmethod Tag.from_buff(buff)

Creates a tag object from data at the beginning of the supplied Buffer object.

Tag.to_obj()

Returns a friendly representation of the tag using only basic Python datatypes. This is a lossy operation, as Python has fewer data types than NBT.

Tag.to_bytes()

Returns a packed version of the tag as a byte string.

Tag.value

The value of the tag.

When working with NBT in relation to a Protocol, the Buffer.unpack_nbt() and Buffer.pack_nbt() methods may be helpful.

Files

You can open an NBT file using the NBTFile class.

class quarry.types.nbt.NBTFile(root_tag)[source]
root_tag = None
classmethod load(path)[source]
save(path)[source]

You can open Minecraft 1.13+ world files (.mca) using the RegionFile class, which can also function as a context manager. See Blocks and Chunks for information on loading block and light data.

class quarry.types.nbt.RegionFile(path)[source]

Experimental support for the Minecraft world storage format (.mca).

close()[source]

Closes the region file.

save_chunk(chunk)[source]

Saves the given chunk, which should be a TagRoot, to the region file.

load_chunk(chunk_x, chunk_z)[source]

Loads the chunk at the given co-ordinates from the region file. The co-ordinates should range from 0 to 31. Returns a TagRoot.

load_chunk_section(chunk_x, chunk_y, chunk_z)[source]

Loads the chunk section at the given co-ordinates from the region file. The co-ordinates should range from 0 to 31. Returns a TagRoot.

Debugging

Call repr(tag) or alt_repr(tag) for a human-readable representation of a tag.

quarry.types.nbt.alt_repr(tag, level=0)[source]

Returns a human-readable representation of a tag using the same format as used the NBT specification.