Class NbtTag
Namespace: Void.Minecraft.Nbt
Assembly: Void.Minecraft.dll
Provides the common API for tags in the Named Binary Tag data model.
public abstract record NbtTag : IEquatable<NbtTag>Inheritance
Derived
NbtByte, NbtByteArray, NbtCompound, NbtDouble, NbtEnd, NbtFloat, NbtInt, NbtIntArray, NbtList, NbtLong, NbtLongArray, NbtShort, NbtString, NbtTag<T>
Implements
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Properties
Name
Gets or sets the optional binary tag name.
public string? Name { get; set; }Property Value
Type
Gets the NBT payload type.
public NbtTagType Type { get; }Property Value
Methods
AsJsonNode()
Serializes this tag to the library’s typed JSON representation.
public JsonNode AsJsonNode()Returns
The JSON node.
AsStream(NbtFormatOptions, bool)
Serializes this tag to a seekable in-memory binary stream.
public MemoryStream AsStream(NbtFormatOptions formatOptions = NbtFormatOptions.BigEndian, bool writeName = true)Parameters
formatOptions NbtFormatOptions
The byte-order and integer-encoding options.
writeName bool
Whether to include the tag-name field.
Returns
A new stream positioned at zero.
Remarks
When writeName is false,
Parse(string)
Parses an SNBT compound or list.
public static NbtTag Parse(string data)Parameters
data string
The SNBT text.
Returns
The parsed compound or list tag.
Exceptions
The trimmed input does not begin with { or [, or contains invalid SNBT.
Parse(ReadOnlyMemory<byte>, out NbtTag, bool, NbtFormatOptions)
Parses one binary NBT tag.
public static long Parse(ReadOnlyMemory<byte> data, out NbtTag result, bool readName = true, NbtFormatOptions formatOptions = NbtFormatOptions.BigEndian)Parameters
data ReadOnlyMemory<byte>
Array-backed binary NBT data.
result NbtTag
The parsed tag.
readName bool
Whether the root tag includes a name field.
formatOptions NbtFormatOptions
The byte-order and integer-encoding options.
Returns
The stream position after the parsed tag.
Exceptions
data is not backed by an accessible array.
Parse<T>(ReadOnlyMemory<byte>, out T, bool, NbtFormatOptions)
Parses one binary NBT tag and requires a specific tag type.
public static long Parse<T>(ReadOnlyMemory<byte> data, out T result, bool readName = true, NbtFormatOptions formatOptions = NbtFormatOptions.BigEndian) where T : NbtTagParameters
data ReadOnlyMemory<byte>
Array-backed binary NBT data.
result T
The parsed tag.
readName bool
Whether the root tag includes a name field.
formatOptions NbtFormatOptions
The byte-order and integer-encoding options.
Returns
The stream position after the parsed tag.
Type Parameters
T
The required tag type.
Exceptions
data is not backed by an accessible array.
The parsed tag is not assignable to T.
ReadFrom<TBuffer>(ref TBuffer, bool)
Reads one binary NBT tag from the current buffer position.
public static NbtTag ReadFrom<TBuffer>(ref TBuffer buffer, bool readName = true) where TBuffer : struct, IMinecraftBuffer<TBuffer>, allows ref structParameters
buffer TBuffer
The buffer to consume.
readName bool
Whether the root tag includes a name field.
Returns
The parsed tag.
Type Parameters
TBuffer
The Minecraft buffer type.
Remarks
The implementation reads the remaining buffer data, then advances the original buffer only by the parsed tag length.
ToSnbt()
Serializes this tag as stringified NBT for derived tag implementations.
protected string ToSnbt()Returns
The SNBT representation.
ToString()
Serializes this tag as stringified NBT.
public override string ToString()Returns
The SNBT representation.
Operators
implicit operator NbtTag(Tag)
Converts a SharpNBT tag to its Void NBT representation.
public static implicit operator NbtTag(Tag tag)Parameters
tag Tag
The SharpNBT tag.
Returns
The corresponding Void tag.
Exceptions
The concrete SharpNBT tag type is unsupported.
implicit operator Tag(NbtTag)
Converts a Void NBT tag to its SharpNBT representation.
public static implicit operator Tag(NbtTag tag)Parameters
tag NbtTag
The Void tag.
Returns
The corresponding SharpNBT tag.
Exceptions
The concrete Void tag type is unsupported.