Modding:WorldGen API: Difference between revisions

From Vintage Story Wiki
Line 357: Line 357:


Our loop and main logic is finished. Now it's time to implement TryGetChestLocation to detect trees.
Our loop and main logic is finished. Now it's time to implement TryGetChestLocation to detect trees.
TODO'
 
 
== Detecting trees ==
Remember the treeTypes variable we created at the top of our class? Now it's time to populate that with the block codes of the tree logs we will be looking for. Let's add a method called LoadTreeTypes.
<syntaxhighlight lang="c#">
private void LoadTreeTypes(ISet<string> treeTypes)
{
    WorldProperty treeTypesFromFile = api.Assets.TryGet("worldproperties/block/wood.json").ToObject<WorldProperty>();
    foreach (WorldPropertyVariant variant in treeTypesFromFile.Variants)
    {
        treeTypes.Add("log-" + variant.Code + "-ud");
    }
}
</syntaxhighlight>
This method reads the log types from worldproperties/block/wood.json and adds them to our treeTypes set. Since we are looking for logs we prepend "log-" and we pick the variant "-ud" which means "Up/Down" since that's the variant of the tree log that is at the base of trees. Now to initialize our treeTypes set just add the following to StartServerSide:
<syntaxhighlight lang="c#">
this.treeTypes = new HashSet<string>();
LoadTreeTypes(treeTypes);
</syntaxhighlight>


== Excercises ==
== Excercises ==
256

edits