Class NbtCompound
Namespace: Void.Minecraft.Nbt.Tags
Assembly: Void.Minecraft.dll
Represents an NBT compound tag backed by a mutable dictionary of named child tags.
public record NbtCompound : NbtTag, IEquatable<NbtTag>, IEquatable<NbtCompound>Inheritance
object ← NbtTag ← NbtCompound
Implements
IEquatable<NbtTag>, IEquatable<NbtCompound>
Inherited Members
NbtTag.Name, NbtTag.Type, NbtTag.AsStream(NbtFormatOptions, bool), NbtTag.AsJsonNode(), NbtTag.ToString(), NbtTag.ToSnbt(), NbtTag.Parse(string), NbtTag.Parse(ReadOnlyMemory<byte>, out NbtTag, bool, NbtFormatOptions), NbtTag.Parse<T>(ReadOnlyMemory<byte>, out T, bool, NbtFormatOptions), NbtTag.ReadFrom<TBuffer>(ref TBuffer, bool), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Constructors
NbtCompound(Dictionary<string, NbtTag>)
Represents an NBT compound tag backed by a mutable dictionary of named child tags.
public NbtCompound(Dictionary<string, NbtTag> Fields)Parameters
Fields Dictionary<string, NbtTag>
The dictionary used as the compound’s backing storage. The dictionary instance is retained directly; changes made through it are reflected by this compound, and existing tag values are not renamed automatically.
NbtCompound()
Creates an empty compound backed by a new dictionary.
public NbtCompound()Properties
Fields
The dictionary used as the compound’s backing storage. The dictionary instance is retained directly; changes made through it are reflected by this compound, and existing tag values are not renamed automatically.
public Dictionary<string, NbtTag> Fields { get; init; }Property Value
this[string]
Gets or replaces a named child tag.
public NbtTag? this[string name] { get; set; }Property Value
Exceptions
The assigned value is null.
The assigned tag instance already occurs elsewhere in this compound.
Methods
ContainsKey(string)
Determines whether the compound contains a key.
public bool ContainsKey(string name)Parameters
name string
The key to locate.
Returns
true when the key exists.
RenameKey(string, string)
Renames an existing field and updates the child tag’s
public void RenameKey(string name, string newName)Parameters
name string
The current key.
newName string
The replacement key.
Exceptions
The source key is absent or the tag instance cannot be inserted at the new key.
ToString()
Serializes this compound as SNBT.
public override string ToString()Returns
The SNBT representation.
TryGetValue(string, out NbtTag)
Attempts to retrieve a child tag by key.
public bool TryGetValue(string name, out NbtTag value)Parameters
name string
The key to locate.
value NbtTag
The child tag when found.
Returns
true when the key exists.
TryRenameKey(string, string)
Attempts to rename a field and update the child tag’s name.
public bool TryRenameKey(string name, string newName)Parameters
name string
The current key.
newName string
The replacement key.
Returns
true when the source existed and was reinserted; otherwise false.
Operators
implicit operator NbtCompound(CompoundTag)
Converts a SharpNBT compound and its children.
public static implicit operator NbtCompound(CompoundTag tag)Parameters
tag CompoundTag
The source compound.
Returns
The converted compound.
implicit operator CompoundTag(NbtCompound)
Converts this compound and its children to SharpNBT.
public static implicit operator CompoundTag(NbtCompound tag)Parameters
tag NbtCompound
The source compound.
Returns
The converted compound.