Skip to content

NbtTag

Namespace Mc.Scripting.Nbt · Kind class (abstract)

public abstract class NbtTag

An NBT value (the data format of block entities, entities, item components and level data). Tags are mutable managed objects: they are copies of the engine’s data, so changing one changes nothing in the world until it is handed back (for example to World.SetBlockEntityData). Use NbtTag.Clone for a deep copy.

Member Description
NbtTag()
protected NbtTag()
Member Description
abstract NbtType Type { get; } The type of this tag.
public abstract NbtType Type { get; }

The type of this tag.

Member Description
abstract NbtTag Clone() A deep copy.
byte[] ToBytes() Serialises the tag to the binary file form (named root with an empty name, big endian).
override string ToString() The tag as stringified NBT (what /data get prints), compact, compound keys sorted.
static bool DeepEquals(NbtTag? a, NbtTag? b) Whether two tags have the same type and contents (compounds compare by keys, not by order).
static NbtTag FromBytes(ReadOnlySpan<byte> data) Parses the binary file form.
static NbtTag Parse(string snbt) Parses stringified NBT ({Health:20.0f,Tags:["a"]}), with the grammar of the game (typed suffixes, quoted strings, [B;1,2] arrays …).
static NbtCompound ParseCompound(string snbt) Parses stringified NBT that must be a compound.
public abstract NbtTag Clone()

A deep copy.

Returns NbtTag: The copy.

public byte[] ToBytes()

Serialises the tag to the binary file form (named root with an empty name, big endian).

Returns byte[]: The bytes.

public override string ToString()

The tag as stringified NBT (what /data get prints), compact, compound keys sorted.

Returns string: The SNBT text.

public static bool DeepEquals(NbtTag? a, NbtTag? b)

Whether two tags have the same type and contents (compounds compare by keys, not by order).

Parameters

Name Type Description
a NbtTag? One tag.
b NbtTag? The other.

Returns bool: True when equal.

public static NbtTag FromBytes(ReadOnlySpan<byte> data)

Parses the binary file form.

Parameters

Name Type Description
data ReadOnlySpan<byte> The bytes (not compressed).

Returns NbtTag: The root tag.

Throws

  • System.FormatException: The data is not valid NBT.
public static NbtTag Parse(string snbt)

Parses stringified NBT ({Health:20.0f,Tags:["a"]}), with the grammar of the game (typed suffixes, quoted strings, [B;1,2] arrays …).

Parameters

Name Type Description
snbt string The text.

Returns NbtTag: The tag.

Throws

  • System.FormatException: The text is not valid SNBT.
public static NbtCompound ParseCompound(string snbt)

Parses stringified NBT that must be a compound.

Parameters

Name Type Description
snbt string The text.

Returns NbtCompound: The compound.

Throws

  • System.FormatException: The text is not valid SNBT or not a compound.
Member Description
static implicit operator NbtTag(sbyte v) An 8 bit integer tag.
static implicit operator NbtTag(short v) A 16 bit integer tag.
static implicit operator NbtTag(int v) A 32 bit integer tag.
static implicit operator NbtTag(long v) A 64 bit integer tag.
static implicit operator NbtTag(float v) A float tag.
static implicit operator NbtTag(double v) A double tag.
static implicit operator NbtTag(string v) A string tag.
static implicit operator NbtTag(bool v) A byte tag holding 1 or 0 (the game stores booleans as bytes).
public static implicit operator NbtTag(sbyte v)

An 8 bit integer tag.

Parameters

Name Type Description
v sbyte The value.

Returns NbtTag

public static implicit operator NbtTag(short v)

A 16 bit integer tag.

Parameters

Name Type Description
v short The value.

Returns NbtTag

public static implicit operator NbtTag(int v)

A 32 bit integer tag.

Parameters

Name Type Description
v int The value.

Returns NbtTag

public static implicit operator NbtTag(long v)

A 64 bit integer tag.

Parameters

Name Type Description
v long The value.

Returns NbtTag

public static implicit operator NbtTag(float v)

A float tag.

Parameters

Name Type Description
v float The value.

Returns NbtTag

public static implicit operator NbtTag(double v)

A double tag.

Parameters

Name Type Description
v double The value.

Returns NbtTag

public static implicit operator NbtTag(string v)

A string tag.

Parameters

Name Type Description
v string The value.

Returns NbtTag

public static implicit operator NbtTag(bool v)

A byte tag holding 1 or 0 (the game stores booleans as bytes).

Parameters

Name Type Description
v bool The value.

Returns NbtTag

NbtCompound · NbtType