Class CompoundTag
Namespace: Void.Minecraft.Nbt
Assembly: Void.Minecraft.dll
Top-level tag that acts as a container for other named tags.
public class CompoundTag : Tag, IEquatable<Tag>, ICloneable, IDictionary<string, Tag>, ICollection<KeyValuePair<string, Tag>>, IEnumerable<KeyValuePair<string, Tag>>, ICollection<Tag>, IEnumerable<Tag>, IEnumerableInheritance
object ← Tag ← CompoundTag
Implements
IEquatable<Tag>, ICloneable, IDictionary<string, Tag>, ICollection<KeyValuePair<string, Tag>>, IEnumerable<KeyValuePair<string, Tag>>, ICollection<Tag>, IEnumerable<Tag>, IEnumerable
Inherited Members
Tag.NoName, Tag.Type, Tag.Parent, Tag.Name, Tag.PrettyPrinted(StringBuilder, int, string), Tag.PrettyName, Tag.WriteJson(Utf8JsonWriter, bool), Tag.WriteJson(Stream, JsonWriterOptions?), Tag.WriteJsonAsync(Stream, JsonWriterOptions?), Tag.ToJson(JsonWriterOptions?), Tag.ToJsonString(bool, string), Tag.Equals(Tag?), Tag.Equals(object?), Tag.GetHashCode(), Tag.Clone(), Tag.Stringify(bool), Tag.StringifyName, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
This along with the
Constructors
CompoundTag(string?)
Creates a new instance of the
public CompoundTag(string? name)Parameters
name string?
The name of the tag, or null if tag has no name.
CompoundTag(string?, IEnumerable<Tag>)
Creates a new instance of the
public CompoundTag(string? name, IEnumerable<Tag> values)Parameters
name string?
The name of the tag, or null if tag has no name.
values IEnumerable<Tag>
A collection
Properties
Count
Removes all items from the
public int Count { get; }Property Value
Exceptions
The
Keys
Gets an
public ICollection<string> Keys { get; }Property Value
Values
Gets an
public ICollection<Tag> Values { get; }Property Value
this[string]
Gets or sets the element with the specified key.
public Tag this[string name] { get; set; }Property Value
Exceptions
key is null.
The property is retrieved and key is not found.
The property is set and the
Methods
Add(string, Tag)
Adds an element with the provided key and value to the
public void Add(string key, Tag value)Parameters
key string
The object to use as the key of the element to add.
value Tag
The object to use as the value of the element to add.
Exceptions
key is null.
An element with the same key already exists in the
The
Add(Tag)
Adds an item to the
public void Add(Tag value)Parameters
value Tag
Exceptions
The
Clear()
Removes all items from the
public void Clear()Exceptions
The
Contains(Tag)
Determines whether the
public bool Contains(Tag tag)Parameters
tag Tag
Returns
true if item is found in the
ContainsKey(string)
Determines whether the
public bool ContainsKey(string key)Parameters
key string
The key to locate in the
Returns
true if the
Exceptions
key is null.
CopyTo(Tag[], int)
Copies the elements of the
public void CopyTo(Tag[] array, int arrayIndex)Parameters
array Tag[]
The one-dimensional
arrayIndex int
The zero-based index in array at which copying begins.
Exceptions
array is null.
arrayIndex is less than 0.
The number of elements in the source arrayIndex to the end of the destination array.
Find<TTag>(string, bool)
Searches the children of this tag, returning the first child with the specified name.
public TTag? Find<TTag>(string name, bool recursive = false) where TTag : TagParameters
name string
The name of the tag to search for.
recursive bool
true to recursively search children, otherwise false to only search direct descendants.
Returns
TTag?
The first tag found with name, otherwise null if none was found.
Type Parameters
TTag
Get<TTag>(string)
public TTag Get<TTag>(string name) where TTag : TagParameters
name string
Returns
TTag
Type Parameters
TTag
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<Tag> GetEnumerator()Returns
An enumerator that can be used to iterate through the collection.
PrettyPrinted(string?)
Retrieves a “pretty-printed” multiline string representing the complete tree structure of the tag.
public string PrettyPrinted(string? indent = " ")Parameters
indent string?
The prefix that will be applied to each indent-level of nested nodes in the tree structure.
Returns
The pretty-printed string.
PrettyPrinted(StringBuilder, int, string)
Writes this tag as a formatted string to the given buffer.
protected override void PrettyPrinted(StringBuilder buffer, int level, string indent)Parameters
buffer StringBuilder
A
level int
The current indent depth to write at.
indent string
The string to use for indents.
Remove(string)
Removes the element with the specified key from the
public bool Remove(string key)Parameters
key string
The key of the element to remove.
Returns
true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original
Exceptions
key is null.
The
Remove(Tag)
Removes the first occurrence of a specific object from the
public bool Remove(Tag item)Parameters
item Tag
The object to remove from the
Returns
true if item was successfully removed from the item is not found in the original
Exceptions
The
Stringify(bool)
Gets the string representation of this NBT tag (SNBT).
public override string Stringify(bool named = true)Parameters
named bool
Flag indicating if the name of the tag should be written.
Returns
This NBT tag in SNBT format.
See Also
https://minecraft.fandom.com/wiki/NBT_format#SNBT_format
Stringify(bool, bool)
Gets the string representation of this NBT tag (SNBT).
public string Stringify(bool topLevel, bool named)Parameters
topLevel bool
Flag indicating if this is the top-level tag that should be wrapped in braces.
named bool
Flag indicating if the name of the NBT should be written.
Returns
This NBT tag in SNBT format.
See Also
https://minecraft.fandom.com/wiki/NBT_format#SNBT_format
ToString()
Returns a string that represents the current object.
public override string ToString()Returns
A string that represents the current object.
TryGetValue(string, out Tag)
Gets the value associated with the specified key.
public bool TryGetValue(string key, out Tag value)Parameters
key string
The key whose value to get.
value Tag
When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
Returns
true if the object that implements
Exceptions
key is null.
TryGetValue<TTag>(string, out TTag)
Gets the value associated with the specified key.
public bool TryGetValue<TTag>(string key, out TTag value) where TTag : TagParameters
key string
The key whose value to get.
value TTag
When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
Returns
true if the object that implements
Type Parameters
TTag
Exceptions
key is null.
WriteJson(Utf8JsonWriter, bool)
Uses the provided writer to write the NBT tag in JSON format.
protected override void WriteJson(Utf8JsonWriter writer, bool named = true)Parameters
writer Utf8JsonWriter
A JSON writer instance.
named bool
Flag indicating if this object’s name should be written as a property name, or false when it
is a child of