Modding:WorldGen API: Difference between revisions

From Vintage Story Wiki
Line 300: Line 300:
I'll explain the treeTypes variable in a bit. Just add it for now.
I'll explain the treeTypes variable in a bit. Just add it for now.


TODO
Replace the empty OnChunkColumnGeneration with the following:
<syntaxhighlight lang="c#">
private void OnChunkColumnGeneration(IServerChunk[] chunks, int chunkX, int chunkZ)
{
    int chestsPlacedCount = 0;
    for (int i = 0; i < chunks.Length; i++)
    {
        if (ShouldPlaceChest())
        {
            BlockPos blockPos = new BlockPos();
            for (int x = 0; x < chunkSize; x++)
            {
                for (int z = 0; z < chunkSize; z++)
                {
                    for (int y = 0; y < worldBlockAccessor.MapSizeY; y++)
                    {
                        if (chestsPlacedCount < MAX_CHESTS_PER_CHUNK)
                        {
                            blockPos.X = chunkX * chunkSize + x;
                            blockPos.Y = y;
                            blockPos.Z = chunkZ * chunkSize + z;
 
                            BlockPos chestLocation = TryGetChestLocation(blockPos);
                            if (chestLocation != null)
                            {
                                bool chestWasPlaced = PlaceTreasureChest(chunkGenBlockAccessor, chestLocation);
                                if (chestWasPlaced)
                                {
                                    chestsPlacedCount++;
                                }
                            }
                        }
                        else//Max chests have been placed for this chunk
                        {
                            return;
                        }
                    }
                }
            }
        }
    }
}
 
private bool ShouldPlaceChest()
{
    int randomNumber = api.World.Rand.Next(0, 100);
    return randomNumber > 0 && randomNumber <= CHEST_SPAWN_PROBABILITY * 100;
}
 
private BlockPos TryGetChestLocation(BlockPos pos)
{
    return null;
}
</syntaxhighlight>


== Excercises ==
== Excercises ==
256

edits