pub struct NbtCompound { /* private fields */ }Expand description
An unordered collection of named NBT tags.
NbtCompound is the primary structured data container in NBT. It maps string names to typed values and is used for virtually all complex game data: items, entities, block entities, player data, level data.
The wire format encodes each entry as: tag type byte + name (u16-prefixed UTF-8) + payload, terminated by an End tag (type 0, no name, no payload).
Uses IndexMap to preserve insertion order (required for deterministic
wire encoding) while providing O(1) lookups instead of O(n) scans.
Implementations§
Source§impl NbtCompound
impl NbtCompound
Sourcepub fn insert(&mut self, name: impl Into<String>, tag: NbtTag)
pub fn insert(&mut self, name: impl Into<String>, tag: NbtTag)
Inserts a named tag into the compound.
If a tag with the same name already exists, it is replaced. The insertion order of new keys is preserved.
Sourcepub fn get(&self, name: &str) -> Option<&NbtTag>
pub fn get(&self, name: &str) -> Option<&NbtTag>
Returns a reference to the tag with the given name, if it exists.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &NbtTag)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &NbtTag)>
Returns an iterator over all (name, tag) pairs in insertion order.
Sourcepub fn contains_key(&self, name: &str) -> bool
pub fn contains_key(&self, name: &str) -> bool
Returns true if the compound contains a tag with the given name.
Trait Implementations§
Source§impl Clone for NbtCompound
impl Clone for NbtCompound
Source§fn clone(&self) -> NbtCompound
fn clone(&self) -> NbtCompound
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NbtCompound
impl Debug for NbtCompound
Source§impl Decode for NbtCompound
Decodes an NbtCompound from network NBT format.
impl Decode for NbtCompound
Decodes an NbtCompound from network NBT format.
Since Minecraft 1.20.3, network NBT uses a simplified root format: a compound tag type byte (0x0A) followed directly by the compound payload (no root tag name). This differs from the traditional NBT format which includes a root tag name.
Fails if the root tag type is not Compound (0x0A).
Source§impl Default for NbtCompound
impl Default for NbtCompound
Source§impl Encode for NbtCompound
Encodes an NbtCompound as a network NBT root compound.
impl Encode for NbtCompound
Encodes an NbtCompound as a network NBT root compound.
Since Minecraft 1.20.3, network NBT uses a simplified root format: a compound tag type byte (0x0A) followed directly by the compound payload (no root tag name). This differs from the traditional NBT format which includes a root tag name after the type byte.
This encoder produces the network NBT format used in modern protocol packets (chat components, item stacks, registry data).
Source§impl EncodedSize for NbtCompound
Computes the wire size of a network NBT root compound.
impl EncodedSize for NbtCompound
Computes the wire size of a network NBT root compound.
Includes the compound type byte (1) plus the compound payload size (entries + End tag).
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Returns 1 (type byte) + payload size.