Skip to content

Class TagBuilder

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

Provides a mechanism for easily building a tree of NBT objects by handling the intermediate step of creating tags, allowing the direct adding of their equivalent values.

All methods return the instance itself, allowing for easily chaining calls to build a document.

public class TagBuilder

Inheritance

objectTagBuilder

Inherited Members

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

Constructors

TagBuilder(string?)

Creates a new instance of the class, optionally with a name to assign the top-level of the final result.

public TagBuilder(string? name = null)

Parameters

name string?

Properties

Depth

Gets the zero-based depth of the current node, indicating how deeply nested it is within other tags.

public int Depth { get; }

Property Value

int

Remarks

The implicit top-level is not factored into this value.

Methods

AddBool(string?, bool)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddBool(string? name, bool value)

Parameters

name string?

The name of the node to add.

value bool

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddBool(bool)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddBool(bool value)

Parameters

value bool

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByte(string?, byte)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddByte(string? name, byte value)

Parameters

name string?

The name of the node to add.

value byte

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByte(string?, int)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddByte(string? name, int value)

Parameters

name string?

The name of the node to add.

value int

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByte(string?, sbyte)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddByte(string? name, sbyte value)

Parameters

name string?

The name of the node to add.

value sbyte

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByte(byte)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddByte(byte value)

Parameters

value byte

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByte(int)

public TagBuilder AddByte(int value)

Parameters

value int

Returns

TagBuilder

AddByte(sbyte)

public TagBuilder AddByte(sbyte value)

Parameters

value sbyte

Returns

TagBuilder

AddByteArray(string?, params byte[])

Adds a new with the specified values to the tree at the current depth.

public TagBuilder AddByteArray(string? name, params byte[] values)

Parameters

name string?

The name of the node to add.

values byte[]

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByteArray(string?, IEnumerable<byte>)

Adds a new with the specified values to the tree at the current depth.

public TagBuilder AddByteArray(string? name, IEnumerable<byte> values)

Parameters

name string?

The name of the node to add.

values IEnumerable<byte>

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByteArray(params byte[])

Adds a new unnamed with the specified values to the tree at the current depth.

public TagBuilder AddByteArray(params byte[] values)

Parameters

values byte[]

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByteArray(IEnumerable<byte>)

Adds a new unnamed with the specified values to the tree at the current depth.

public TagBuilder AddByteArray(IEnumerable<byte> values)

Parameters

values IEnumerable<byte>

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByteArray(string?, params sbyte[])

Adds a new with the specified values to the tree at the current depth.

public TagBuilder AddByteArray(string? name, params sbyte[] values)

Parameters

name string?

The name of the node to add.

values sbyte[]

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByteArray(string?, IEnumerable<sbyte>)

Adds a new with the specified values to the tree at the current depth.

public TagBuilder AddByteArray(string? name, IEnumerable<sbyte> values)

Parameters

name string?

The name of the node to add.

values IEnumerable<sbyte>

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByteArray(params sbyte[])

Adds a new unnamed with the specified values to the tree at the current depth.

public TagBuilder AddByteArray(params sbyte[] values)

Parameters

values sbyte[]

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddByteArray(IEnumerable<sbyte>)

Adds a new unnamed with the specified values to the tree at the current depth.

public TagBuilder AddByteArray(IEnumerable<sbyte> values)

Parameters

values IEnumerable<sbyte>

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddDouble(string?, double)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddDouble(string? name, double value)

Parameters

name string?

The name of the node to add.

value double

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddDouble(double)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddDouble(double value)

Parameters

value double

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddFloat(string?, float)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddFloat(string? name, float value)

Parameters

name string?

The name of the node to add.

value float

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddFloat(float)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddFloat(float value)

Parameters

value float

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddInt(string?, int)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddInt(string? name, int value)

Parameters

name string?

The name of the node to add.

value int

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddInt(string?, uint)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddInt(string? name, uint value)

Parameters

name string?

The name of the node to add.

value uint

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddInt(int)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddInt(int value)

Parameters

value int

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddInt(uint)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddInt(uint value)

Parameters

value uint

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddIntArray(string?, params int[])

Adds a new with the specified values to the tree at the current depth.

public TagBuilder AddIntArray(string? name, params int[] values)

Parameters

name string?

The name of the node to add.

values int[]

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddIntArray(string?, IEnumerable<int>)

Adds a new with the specified values to the tree at the current depth.

public TagBuilder AddIntArray(string? name, IEnumerable<int> values)

Parameters

name string?

The name of the node to add.

values IEnumerable<int>

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddIntArray(params int[])

Adds a new unnamed with the specified values to the tree at the current depth.

public TagBuilder AddIntArray(params int[] values)

Parameters

values int[]

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddIntArray(IEnumerable<int>)

Adds a new unnamed with the specified values to the tree at the current depth.

public TagBuilder AddIntArray(IEnumerable<int> values)

Parameters

values IEnumerable<int>

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddLong(string?, long)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddLong(string? name, long value)

Parameters

name string?

The name of the node to add.

value long

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddLong(string?, ulong)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddLong(string? name, ulong value)

Parameters

name string?

The name of the node to add.

value ulong

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddLong(long)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddLong(long value)

Parameters

value long

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddLong(ulong)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddLong(ulong value)

Parameters

value ulong

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddLongArray(string?, params long[])

Adds a new with the specified values to the tree at the current depth.

public TagBuilder AddLongArray(string? name, params long[] values)

Parameters

name string?

The name of the node to add.

values long[]

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddLongArray(string?, IEnumerable<long>)

Adds a new with the specified values to the tree at the current depth.

public TagBuilder AddLongArray(string? name, IEnumerable<long> values)

Parameters

name string?

The name of the node to add.

values IEnumerable<long>

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddLongArray(params long[])

Adds a new unnamed with the specified values to the tree at the current depth.

public TagBuilder AddLongArray(params long[] values)

Parameters

values long[]

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddLongArray(IEnumerable<long>)

Adds a new unnamed with the specified values to the tree at the current depth.

public TagBuilder AddLongArray(IEnumerable<long> values)

Parameters

values IEnumerable<long>

The value(s) that will be included in the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddShort(string?, short)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddShort(string? name, short value)

Parameters

name string?

The name of the node to add.

value short

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddShort(string?, int)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddShort(string? name, int value)

Parameters

name string?

The name of the node to add.

value int

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddShort(string?, ushort)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddShort(string? name, ushort value)

Parameters

name string?

The name of the node to add.

value ushort

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddShort(short)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddShort(short value)

Parameters

value short

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddShort(int)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddShort(int value)

Parameters

value int

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddShort(ushort)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddShort(ushort value)

Parameters

value ushort

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddString(string?, string?)

Adds a new with the specified name and value to the tree at the current depth.

public TagBuilder AddString(string? name, string? value)

Parameters

name string?

The name of the node to add.

value string?

The value of the tag.

Returns

TagBuilder

AddString(string?)

Adds a new unnamed with the specified value to the tree at the current depth.

public TagBuilder AddString(string? value)

Parameters

value string?

The value of the tag.

Returns

TagBuilder

Returns this instance for chaining.

AddTag(Tag)

Adds an existing object to the tree at the current depth.

public TagBuilder AddTag(Tag tag)

Parameters

tag Tag

The instance to add.

Returns

TagBuilder

Returns this instance for chaining.

Exceptions

ArgumentException

Thrown if adding to a node, and the type does not match.

ArgumentNullException

Thrown when tag is null.

BeginCompound(string?)

Opens a new section, increasing the current depth level by one.

public TagBuilder BeginCompound(string? name = null)

Parameters

name string?

The name to apply to the , or null to omit a name.

Returns

TagBuilder

Returns this instance for chaining.

See Also

TagBuilder.EndCompound()

BeginList(TagType, string?)

Opens a new section, increasing the current depth level by one.

public TagBuilder BeginList(TagType childType, string? name = null)

Parameters

childType TagType

The of the child items this list will contain.

name string?

The name to apply to the , or null to omit a name.

Returns

TagBuilder

Returns this instance for chaining.

See Also

TagBuilder.EndList()

Create()

Closes any open compound/list sections, and returns the result as a .

public CompoundTag Create()

Returns

CompoundTag

A representing the result of this tree.

Remarks

Invoking this method moves the current back to the top-level.

End()

Closes the current or section and decreases the by one.

public TagBuilder End()

Returns

TagBuilder

Returns this instance for chaining.

Remarks

This method does nothing if the current location is already at the top-level.

EndCompound()

Closes the current section and decreases the by one. Does nothing if the current node does not represent a .

public TagBuilder EndCompound()

Returns

TagBuilder

Returns this instance for chaining.

See Also

TagBuilder.BeginCompound(string?)

EndList()

Closes the current section and decreases the by one. Does nothing if the current node does not represent a .

public TagBuilder EndList()

Returns

TagBuilder

Returns this instance for chaining.

See Also

TagBuilder.BeginList(TagType, string?)

NewCompound(string?)

Creates a new and pushes it to the current scope level, returning a object that pulls the current scope back out one level when disposed.

public TagBuilder.Context NewCompound(string? name)

Parameters

name string?

The name to apply to the , or null to omit a name.

Returns

TagBuilder.Context

A that will close the when disposed.

Remarks

This is essentially no different than and but can use using blocks to distinguish scope.

NewList(TagType, string?)

Creates a new and pushes it to the current scope level, returning a object that pulls the current scope back out one level when disposed.

public TagBuilder.Context NewList(TagType childType, string? name)

Parameters

childType TagType

The of the child items this list will contain.

name string?

The name to apply to the , or null to omit a name.

Returns

TagBuilder.Context

A that will close the when disposed.

Remarks

This is essentially no different than and but can use using blocks to distinguish scope.