Modding:WorldGen API: Difference between revisions

From Vintage Story Wiki
Line 285: Line 285:


== Finding where to place the chest ==
== Finding where to place the chest ==
Now we are ready to place code in our OnChunkColumnGeneration to find a suitable spot for our chest. We are going to set up a nested for loop to loop through each x,y,z location in the chunk and see if that spot is beside a tree. Before we set up our loop we are going to add a few more variables at the top of our class.
<syntaxhighlight lang="c#">
private const int MAX_CHESTS_PER_CHUNK = 1;
private const float CHEST_SPAWN_PROBABILITY = 0.80f;
private int chunkSize;
private ISet<string> treeTypes;
</syntaxhighlight>
They are mostly self explanatory. The first one indicates how many chests we are going to allow to be placed per chunk. CHEST_SPAWN_PROBABILITY is a probability of placing a chest in the current chunk at all. chunkSize is just stored as a convenient way to access chunkSize. To initialize it we need the following in StartServerSide:
<syntaxhighlight lang="c#">
this.chunkSize = worldBlockAccessor.ChunkSize;
</syntaxhighlight>
Make sure to add this after you set worldBlockAccessor!
I'll explain the treeTypes variable in a bit. Just add it for now.
TODO
TODO


== Excercises ==
== Excercises ==
256

edits