Modding:WorldGen API: Difference between revisions

From Vintage Story Wiki
Line 218: Line 218:


== Hooking in to the world gen API ==
== Hooking in to the world gen API ==
The IServerEventAPI has a method called ChunkColumnGeneration that allows you to pass a delegate just like we did for our /treasure command. However, the method signature for this is different.
Hooking into the world gen api is very similar to how we registered our command. We will pass a delegate callback that gets called when a chunk column is generated.
TODO:


Add the following to StartServerSide
<syntaxhighlight lang="c#">
this.api.Event.ChunkColumnGeneration(OnChunkColumnGeneration, EnumWorldGenPass.Vegetation);
</syntaxhighlight>
The first argument is a delegate, which is a reference to a method. You will get a compiler error after adding that line because we have not yet created the OnChunkColumnGeneration method. We will create that next. The second argument is an Enum that indicates which world generation pass we need to hook into. Vintage story uses several passes to generate the world. Different features are available during different world gen passes. Since we will be placing chests next to trees, we need trees to be in the world so we choose to be notified during the EnumWorldGenPass.Vegetation which tells the engine that we need neighbor chunks, block layers, tall grass, bushes and trees to be available.
<syntaxhighlight lang="c#">
private void OnChunkColumnGeneration(IServerChunk[] chunks, int chunkX, int chunkZ)
{
}
</syntaxhighlight>


== Finding where to place the chest ==
== Finding where to place the chest ==