Skip to content

Class Tag

Namespace: Void.Minecraft.Nbt
Assembly: Void.Minecraft.dll

Abstract base class that all NBT tags inherit from.

public abstract class Tag : IEquatable<Tag>, ICloneable

Inheritance

objectTag

Derived

ArrayTag<T>, BoolTag, CompoundTag, EndTag, ListTag, NumericTag<T>, StringTag

Implements

IEquatable<Tag>, ICloneable

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

Tag(TagType, string?)

Initializes a new instance of the class.

protected Tag(TagType type, string? name)

Parameters

type TagType

A constant describing the NBT type for this tag.

name string?

The name of the tag, or null if tag has no name.

Fields

NoName

Text applied in a pretty-print string when a tag has no defined value.

protected const string NoName = "None"

Field Value

string

Properties

Name

Gets the name assigned to this .

public string? Name { get; }

Property Value

string?

Parent

Gets the parent this object is a child of.

[Obsolete("Parent property may be removed in a future version.")]
public Tag? Parent { get; }

Property Value

Tag?

PrettyName

Gets the name of the object as a human-readable quoted string, or a default name to indicate it has no name when applicable.

protected string PrettyName { get; }

Property Value

string

StringifyName

Gets the name in a formatted properly for SNBT.

protected string StringifyName { get; }

Property Value

string

Type

Gets a constant describing the NBT type this object represents.

public TagType Type { get; }

Property Value

TagType

Methods

Clone()

Creates a new object that is a copy of the current instance.

public object Clone()

Returns

object

A new object that is a copy of this instance.

Equals(Tag?)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Tag? other)

Parameters

other Tag?

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object?

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

PrettyPrinted(StringBuilder, int, string)

Writes this tag as a formatted string to the given buffer.

protected virtual void PrettyPrinted(StringBuilder buffer, int level, string indent)

Parameters

buffer StringBuilder

A instance to write to.

level int

The current indent depth to write at.

indent string

The string to use for indents.

Stringify(bool)

Gets the string representation of this NBT tag (SNBT).

public abstract string Stringify(bool named = true)

Parameters

named bool

Flag indicating if the name of the tag should be written.

Returns

string

This NBT tag in SNBT format.

See Also

https://minecraft.fandom.com/wiki/NBT_format#SNBT_format

ToJson(JsonWriterOptions?)

Converts the NBT to an equivalent JSON representation, and returns it as a string.

public string ToJson(JsonWriterOptions? options = null)

Parameters

options JsonWriterOptions?

Options that will be passed to the JSON writer.

Returns

string

The JSON-encoded string representing describing the tag.

ToJsonString(bool, string)

Gets a representation of this as a JSON string.

[Obsolete("Use WriteJson and ToJson instead.")]
public string ToJsonString(bool pretty = false, string indent = " ")

Parameters

pretty bool

Flag indicating if formatting should be applied to make the string human-readable.

indent string

Ignored

Returns

string

A JSON string describing this object.

WriteJson(Utf8JsonWriter, bool)

Uses the provided writer to write the NBT tag in JSON format.

protected abstract 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 , in which case it should be written as a JSON array element.

WriteJson(Stream, JsonWriterOptions?)

Writes the tag to the specified stream in JSON format.

public void WriteJson(Stream stream, JsonWriterOptions? options = null)

Parameters

stream Stream

The stream instance to write to.

options JsonWriterOptions?

Options that will be passed to the JSON writer.

Exceptions

IOException

The stream is no opened for writing.

WriteJsonAsync(Stream, JsonWriterOptions?)

Asynchronously writes the tag to the specified stream in JSON format.

public Task WriteJsonAsync(Stream stream, JsonWriterOptions? options = null)

Parameters

stream Stream

The stream instance to write to.

options JsonWriterOptions?

Options that will be passed to the JSON writer.

Returns

Task

Exceptions

IOException

The stream is no opened for writing.

Operators

operator ==(Tag?, Tag?)

Tests for equality of this object with another instance.

public static bool operator ==(Tag? left, Tag? right)

Parameters

left Tag?

First value to compare.

right Tag?

Second value to compare.

Returns

bool

Result of comparison.

operator !=(Tag?, Tag?)

Tests for inequality of this object with another instance.

public static bool operator !=(Tag? left, Tag? right)

Parameters

left Tag?

First value to compare.

right Tag?

Second value to compare.

Returns

bool

Result of comparison.