Table of Contents

Class TreeAttribute

Namespace
Vintagestory.API.Datastructures
Assembly
VintagestoryAPI.dll

A datastructure to hold generic data for most primitives (int, string, float, etc.). But can also hold generic data using the ByteArrayAttribute + class serialization

public class TreeAttribute : ITreeAttribute, IAttribute, IEnumerable<KeyValuePair<string, IAttribute>>, IEnumerable
Inheritance
TreeAttribute
Implements
Derived
Inherited Members
Extension Methods

Constructors

TreeAttribute()

public TreeAttribute()

Fields

AttributeIdMapping

public static Dictionary<int, Type> AttributeIdMapping

Field Value

Dictionary<int, Type>

depth

protected int depth

Field Value

int

Properties

Count

Amount of elements in this Tree attribute

public int Count { get; }

Property Value

int

this[string]

Will return null if given attribute does not exist

public IAttribute this[string key] { get; set; }

Parameters

key string

Property Value

IAttribute

Keys

public string[] Keys { get; }

Property Value

string[]

Values

Returns all values inside this tree attributes

public IAttribute[] Values { get; }

Property Value

IAttribute[]

Methods

Clone()

Creates a deep copy of the attribute tree

public virtual ITreeAttribute Clone()

Returns

ITreeAttribute

CreateFromBytes(byte[])

public static TreeAttribute CreateFromBytes(byte[] blockEntityData)

Parameters

blockEntityData byte[]

Returns

TreeAttribute

DeleteAttributeByPath(string)

public void DeleteAttributeByPath(string path)

Parameters

path string

Equals(IWorldAccessor, IAttribute)

Returns true if given tree exactly matches this one

public bool Equals(IWorldAccessor worldForResolve, IAttribute other)

Parameters

worldForResolve IWorldAccessor
other IAttribute

Returns

bool

Equals(IWorldAccessor, IAttribute, string, params string[])

public bool Equals(IWorldAccessor worldForResolve, IAttribute other, string currentPath, params string[] ignorePaths)

Parameters

worldForResolve IWorldAccessor
other IAttribute
currentPath string
ignorePaths string[]

Returns

bool

Equals(IWorldAccessor, IAttribute, params string[])

public bool Equals(IWorldAccessor worldForResolve, IAttribute other, params string[] ignorePaths)

Parameters

worldForResolve IWorldAccessor
other IAttribute
ignorePaths string[]

Returns

bool

FromBytes(byte[])

public virtual void FromBytes(byte[] data)

Parameters

data byte[]

FromBytes(BinaryReader)

public virtual void FromBytes(BinaryReader stream)

Parameters

stream BinaryReader

FromJson(string)

public static IAttribute FromJson(string json)

Parameters

json string

Returns

IAttribute

GetAsBool(string, bool)

Returns true/false, for whatever type of attribute is found for given key

public virtual bool GetAsBool(string key, bool defaultValue = false)

Parameters

key string
defaultValue bool

Returns

bool

GetAsInt(string, int)

Same as (int)GetDecimal(key, defValue);

public virtual int GetAsInt(string key, int defaultValue = 0)

Parameters

key string
defaultValue int

Returns

int

GetAsString(string, string)

Retrieves the value of given attribute, independent of attribute type

public virtual string GetAsString(string key, string defaultValue = null)

Parameters

key string
defaultValue string

Returns

string

GetAttribute(string)

public IAttribute GetAttribute(string key)

Parameters

key string

Returns

IAttribute

GetAttributeByPath(string)

public IAttribute GetAttributeByPath(string path)

Parameters

path string

Returns

IAttribute

GetAttributeId()

public int GetAttributeId()

Returns

int

GetBool(string, bool)

Retrieves a bool or default value if key is not found

public virtual bool GetBool(string key, bool defaultValue = false)

Parameters

key string
defaultValue bool

Returns

bool

GetBytes(string, byte[])

Retrieves a byte array or defaultValue if key is not found

public virtual byte[] GetBytes(string key, byte[] defaultValue = null)

Parameters

key string
defaultValue byte[]

Returns

byte[]

GetDecimal(string, double)

Retrieves an int, float, long or double value. Whatever attribute is found for given key, in aformentioned order. If its a string its converted to double

public virtual double GetDecimal(string key, double defaultValue = 0)

Parameters

key string
defaultValue double

Returns

double

GetDouble(string, double)

Retrieves a double or defaultValue if key is not found

public virtual double GetDouble(string key, double defaultValue = 0)

Parameters

key string
defaultValue double

Returns

double

GetEnumerator()

public IEnumerator<KeyValuePair<string, IAttribute>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<string, IAttribute>>

GetFloat(string, float)

Retrieves a float or defaultvalue if key is not found

public virtual float GetFloat(string key, float defaultValue = 0)

Parameters

key string
defaultValue float

Returns

float

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetHashCode(string[])

public int GetHashCode(string[] ignoredAttributes)

Parameters

ignoredAttributes string[]

Returns

int

GetInt(string, int)

Retrieves an int or default value if key is not found

public virtual int GetInt(string key, int defaultValue = 0)

Parameters

key string
defaultValue int

Returns

int

GetItemstack(string, ItemStack)

Retrieves an itemstack or defaultValue if key is not found. Be sure to call stack.ResolveBlockOrItem() after retrieving it.

public ItemStack GetItemstack(string key, ItemStack defaultValue = null)

Parameters

key string
defaultValue ItemStack

Returns

ItemStack

GetLong(string, long)

Retrieves a long or default value if key is not found

public virtual long GetLong(string key, long defaultValue = 0)

Parameters

key string
defaultValue long

Returns

long

GetModelTransform(string)

public virtual ModelTransform GetModelTransform(string key)

Parameters

key string

Returns

ModelTransform

GetOrAddTreeAttribute(string)

Retrieves an attribute tree or adds it if key is not found. Throws an exception if the key does exist but is not a tree.

public virtual ITreeAttribute GetOrAddTreeAttribute(string key)

Parameters

key string

Returns

ITreeAttribute

GetString(string, string)

Retrieves a string attribute or defaultValue if key is not found

public virtual string GetString(string key, string defaultValue = null)

Parameters

key string
defaultValue string

Returns

string

GetStringArray(string, string[])

Retrieves a string or defaultValue if key is not found

public virtual string[] GetStringArray(string key, string[] defaultValue = null)

Parameters

key string
defaultValue string[]

Returns

string[]

GetTreeAttribute(string)

Retrieves an attribute tree or null if key is not found

public virtual ITreeAttribute GetTreeAttribute(string key)

Parameters

key string

Returns

ITreeAttribute

GetValue()

public object GetValue()

Returns

object

HasAttribute(string)

True if this attribute exists

public bool HasAttribute(string key)

Parameters

key string

Returns

bool

IndexOf(string)

[Obsolete("May not return consistent results if the TreeAttribute changes between calls")]
public int IndexOf(string key)

Parameters

key string

Returns

int

IsSubSetOf(IWorldAccessor, IAttribute)

Returns true if given tree contains all of elements of this one, but given tree may contain also more elements. Individual node values are exactly matched.

public bool IsSubSetOf(IWorldAccessor worldForResolve, IAttribute other)

Parameters

worldForResolve IWorldAccessor
other IAttribute

Returns

bool

MergeAttribute(TreeAttribute, string, IAttribute)

protected static void MergeAttribute(TreeAttribute dstTree, string srcKey, IAttribute srcAttr)

Parameters

dstTree TreeAttribute
srcKey string
srcAttr IAttribute

MergeTree(ITreeAttribute)

Merges the sourceTree into the current one

public virtual void MergeTree(ITreeAttribute sourceTree)

Parameters

sourceTree ITreeAttribute

MergeTree(TreeAttribute, TreeAttribute)

protected static void MergeTree(TreeAttribute dstTree, TreeAttribute srcTree)

Parameters

dstTree TreeAttribute
srcTree TreeAttribute

RegisterAttribute(int, Type)

public static void RegisterAttribute(int attrId, Type type)

Parameters

attrId int
type Type

RemoveAttribute(string)

Removes an attribute

public virtual void RemoveAttribute(string key)

Parameters

key string

Set(string, IAttribute)

Set a value. Returns itself for method chaining

public TreeAttribute Set(string key, IAttribute value)

Parameters

key string
value IAttribute

Returns

TreeAttribute

SetAttribute(string, IAttribute)

public virtual void SetAttribute(string key, IAttribute value)

Parameters

key string
value IAttribute

SetBool(string, bool)

Creates a bool attribute with given key and value

public virtual void SetBool(string key, bool value)

Parameters

key string
value bool

SetBytes(string, byte[])

Creates a byte[] attribute with given key and value

public virtual void SetBytes(string key, byte[] value)

Parameters

key string
value byte[]

SetDouble(string, double)

Creates a double attribute with given key and value

public virtual void SetDouble(string key, double value)

Parameters

key string
value double

SetFloat(string, float)

Creates a float attribute with given key and value
Side note: If you need this attribute to be compatible with deserialized json - use SetDouble()

public virtual void SetFloat(string key, float value)

Parameters

key string
value float

SetInt(string, int)

Creates an int attribute with given key and value
Side note: If you need this attribute to be compatible with deserialized json - use SetLong()

public virtual void SetInt(string key, int value)

Parameters

key string
value int

SetItemstack(string, ItemStack)

Sets given item stack with given key

public void SetItemstack(string key, ItemStack itemstack)

Parameters

key string
itemstack ItemStack

SetLong(string, long)

Creates a long attribute with given key and value

public virtual void SetLong(string key, long value)

Parameters

key string
value long

SetString(string, string)

Creates a string attribute with given key and value

public virtual void SetString(string key, string value)

Parameters

key string
value string

SetStringArray(string, string[])

public virtual void SetStringArray(string key, string[] values)

Parameters

key string
values string[]

SortedCopy(bool)

Returns a ITreeAttribute sorted alphabetically by key. Does not modify the existing ITreeAttribute

public OrderedDictionary<string, IAttribute> SortedCopy(bool recursive = false)

Parameters

recursive bool

Returns

OrderedDictionary<string, IAttribute>

ToBytes()

public virtual byte[] ToBytes()

Returns

byte[]

ToBytes(BinaryWriter)

public virtual void ToBytes(BinaryWriter stream)

Parameters

stream BinaryWriter

ToJsonToken()

public string ToJsonToken()

Returns

string

ToJsonToken(IEnumerable<KeyValuePair<string, IAttribute>>)

public static string ToJsonToken(IEnumerable<KeyValuePair<string, IAttribute>> attributes)

Parameters

attributes IEnumerable<KeyValuePair<string, IAttribute>>

Returns

string

TryGetAttribute(string, out IAttribute)

Similar to TryGetValue for a Dictionary

public bool TryGetAttribute(string key, out IAttribute value)

Parameters

key string
value IAttribute

Returns

bool

TryGetBool(string)

Retrieves a bool or null if the key is not found

public virtual bool? TryGetBool(string key)

Parameters

key string

Returns

bool?

TryGetDouble(string)

Retrieves a double or null if key is not found

public virtual double? TryGetDouble(string key)

Parameters

key string

Returns

double?

TryGetFloat(string)

Retrieves a float or null if the key is not found

public virtual float? TryGetFloat(string key)

Parameters

key string

Returns

float?

TryGetInt(string)

Retrieves an int or null if the key is not found

public virtual int? TryGetInt(string key)

Parameters

key string

Returns

int?

TryGetLong(string)

Retrieves a long or null value if key is not found

public virtual long? TryGetLong(string key)

Parameters

key string

Returns

long?