NbtCompound
Namespace Mc.Scripting.Nbt · Kind class (sealed)
public sealed class NbtCompound : NbtTag, IEnumerable, IEnumerable<KeyValuePair<string, NbtTag>>A compound: named tags (keys are unique; the enumeration order is the insertion order).
Constructors
Section titled “Constructors”| Member | Description |
|---|---|
NbtCompound() |
Constructor
Section titled “Constructor”public NbtCompound()Properties
Section titled “Properties”| Member | Description |
|---|---|
int Count { get; } |
Number of entries. |
IEnumerable<string> Keys { get; } |
The keys. |
override NbtType Type { get; } |
public int Count { get; }Number of entries.
public IEnumerable<string> Keys { get; }The keys.
public override NbtType Type { get; }Indexers
Section titled “Indexers”| Member | Description |
|---|---|
NbtTag this[string key] { get; set; } |
Gets or sets an entry. |
this[]
Section titled “this[]”public NbtTag this[string key] { get; set; }Gets or sets an entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
Throws
System.Collections.Generic.KeyNotFoundException: Reading a key that does not exist.
Methods
Section titled “Methods”public void Clear()Removes every entry.
public override NbtTag Clone()Returns NbtTag
Contains
Section titled “Contains”public bool Contains(string key)Whether a key exists.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
Returns bool: True when present.
Get<T>
Section titled “Get<T>”public T? Get<T>(string key) where T : NbtTagGets an entry of a given type.
Type parameters
T: The tag class (for exampleNbtCompound).
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
Returns T?: The tag, or null when the key is missing or has another type.
GetBool
Section titled “GetBool”public bool GetBool(string key, bool fallback = false)Reads a boolean (a non-zero numeric entry).
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
fallback |
bool = false |
What to return when the key is missing. |
Returns bool: The value.
GetCompound
Section titled “GetCompound”public NbtCompound? GetCompound(string key)Reads a compound entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
Returns NbtCompound?: The compound, or null.
GetDouble
Section titled “GetDouble”public double GetDouble(string key, double fallback = 0)Reads a numeric entry as a double.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
fallback |
double = 0 |
What to return when the key is missing or not numeric. |
Returns double: The value.
GetEnumerator
Section titled “GetEnumerator”public IEnumerator<KeyValuePair<string, NbtTag>> GetEnumerator()Returns IEnumerator<KeyValuePair<string, NbtTag>>
GetInt
Section titled “GetInt”public int GetInt(string key, int fallback = 0)Reads a numeric entry as an int.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
fallback |
int = 0 |
What to return when the key is missing or not numeric. |
Returns int: The value.
GetList
Section titled “GetList”public NbtList? GetList(string key)Reads a list entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
Returns NbtList?: The list, or null.
GetLong
Section titled “GetLong”public long GetLong(string key, long fallback = 0)Reads a numeric entry as a long (any integer or float type; floats are truncated).
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
fallback |
long = 0 |
What to return when the key is missing or not numeric. |
Returns long: The value.
GetString
Section titled “GetString”public string GetString(string key, string fallback = "")Reads a string entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
fallback |
string = "" |
What to return when the key is missing or not a string. |
Returns string: The value.
public NbtCompound Merge(NbtCompound other)Deep-merges another compound into this one: nested compounds merge, everything else is copied (like /data merge).
Parameters
| Name | Type | Description |
|---|---|---|
other |
NbtCompound |
The compound to merge in. |
Returns NbtCompound: This compound.
public NbtCompound Put(string key, NbtTag tag)Adds or replaces an entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
tag |
NbtTag |
The tag. |
Returns NbtCompound: This compound, for chaining.
PutBool
Section titled “PutBool”public NbtCompound PutBool(string key, bool value)Sets a byte entry (the game’s boolean).
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
value |
bool |
The value. |
Returns NbtCompound: This compound.
PutByte
Section titled “PutByte”public NbtCompound PutByte(string key, sbyte value)Sets a byte entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
value |
sbyte |
The value. |
Returns NbtCompound: This compound.
PutDouble
Section titled “PutDouble”public NbtCompound PutDouble(string key, double value)Sets a double entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
value |
double |
The value. |
Returns NbtCompound: This compound.
PutFloat
Section titled “PutFloat”public NbtCompound PutFloat(string key, float value)Sets a float entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
value |
float |
The value. |
Returns NbtCompound: This compound.
PutInt
Section titled “PutInt”public NbtCompound PutInt(string key, int value)Sets an int entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
value |
int |
The value. |
Returns NbtCompound: This compound.
PutLong
Section titled “PutLong”public NbtCompound PutLong(string key, long value)Sets a long entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
value |
long |
The value. |
Returns NbtCompound: This compound.
PutShort
Section titled “PutShort”public NbtCompound PutShort(string key, short value)Sets a short entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
value |
short |
The value. |
Returns NbtCompound: This compound.
PutString
Section titled “PutString”public NbtCompound PutString(string key, string value)Sets a string entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
value |
string |
The value. |
Returns NbtCompound: This compound.
Remove
Section titled “Remove”public bool Remove(string key)Removes an entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
Returns bool: True when it existed.
TryGet
Section titled “TryGet”public bool TryGet(string key, out NbtTag tag)Gets an entry.
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
The key. |
tag |
out NbtTag |
The tag when present. |
Returns bool: Whether the key exists.