Modding:TreeAttribute: Difference between revisions
Ninjanomnom (talk | contribs) m (Double checked information and added version) |
Mirotworez (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
{{GameVersion|1.15}} | {{GameVersion|1.15}} | ||
<languages/><translate> | |||
A TreeAttribute is a nested data structure whose primary purpose is to store data. It can hold generic data for most primitives, such as int, string, float, as well as more complex types like ItemStacks and other TreeAttributes (hence a nested structure). | A TreeAttribute is a nested data structure whose primary purpose is to store data. It can hold generic data for most primitives, such as int, string, float, as well as more complex types like ItemStacks and other TreeAttributes (hence a nested structure). | ||
Line 33: | Line 33: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
For documentation, see [http://apidocs.vintagestory.at/api/Vintagestory.API.Datastructures.TreeAttribute.html TreeAttribute] and [http://apidocs.vintagestory.at/api/Vintagestory.API.Datastructures.ITreeAttribute.html ITreeAttribute]. | For documentation, see [http://apidocs.vintagestory.at/api/Vintagestory.API.Datastructures.TreeAttribute.html TreeAttribute] and [http://apidocs.vintagestory.at/api/Vintagestory.API.Datastructures.ITreeAttribute.html ITreeAttribute]. | ||
</translate> | |||
{{Navbox/modding|Vintage Story}} | {{Navbox/modding|Vintage Story}} |
Revision as of 06:49, 19 September 2022
This page was last verified for Vintage Story version 1.15.
A TreeAttribute is a nested data structure whose primary purpose is to store data. It can hold generic data for most primitives, such as int, string, float, as well as more complex types like ItemStacks and other TreeAttributes (hence a nested structure).
Additionally you can store data as byte[]
if it is not supported by the TreeAttribute itself (for this you could use Vintagestory.API.Util.SerializerUtil
).
Attributes are written and read via keys.
To use TreeAttribute, add the using statement for Vintagestory.API.Datastructures.
Use in API
Within the API, TreeAttribute is often employed to store persistent entity data (items a basket contains, content of a barrel/bucket) and to access data extracted from JSON files. TreeAttribute is often supplied as the interface ITreeAttribute.
Example in code
using Vintagestory.API.Datastructures;
class Example
{
Example()
{
// Setting and getting values
TreeAttribute tree;
tree = new TreeAttribute();
float someValue = 0.35f;
string someKey = "valueKey";
// Set the value
tree.SetFloat(someKey, someValue);
// Retrieve the value
tree.GetFloat(someKey);
}
}
For documentation, see TreeAttribute and ITreeAttribute.
Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.
Modding | |
---|---|
Modding Introduction | Getting Started • Theme Pack |
Content Modding | Content Mods • Developing a Content Mod • Basic Tutorials • Intermediate Tutorials • Advanced Tutorials • Content Mod Concepts |
Code Modding | Code Mods • Setting up your Development Environment |
Property Overview | Item • Entity • Entity Behaviors • Block • Block Behaviors • Block Classes • Block Entities • Block Entity Behaviors • Collectible Behaviors • World properties |
Workflows & Infrastructure | Modding Efficiency Tips • Mod-engine compatibility • Mod Extensibility • VS Engine |
Additional Resources | Community Resources • Modding API Updates • Programming Languages • List of server commands • List of client commands • Client startup parameters • Server startup parameters Example Mods • API Docs • GitHub Repository |