WorldGen: Difference between revisions

From Vintage Story Wiki
No edit summary
Line 2: Line 2:
== Intro ==
== Intro ==


We will be walking through how plug in and add your own features to the world generation code of Vintage Story by looking at a demo mod called VSTreasureChest. The code for this project can be found here [https://github.com/anegostudios/VSTreasureChest] but we are going to walk through coding it from scratch.
We will be walking through how plug in and add your own features to the world generation code of Vintage Story by looking at a demo mod called VSTreasureChest. The code for this project can be found here [https://github.com/anegostudios/VSTreasureChest] but we are going to walk through coding it from scratch. Please note that it is assumed that you are familiar with basic C# concepts. This document is strictly intended to familiarize you with the basic world gen api.


== VSTreasureChest ==
== VSTreasureChest ==

Revision as of 02:32, 19 February 2017

Intro

We will be walking through how plug in and add your own features to the world generation code of Vintage Story by looking at a demo mod called VSTreasureChest. The code for this project can be found here [1] but we are going to walk through coding it from scratch. Please note that it is assumed that you are familiar with basic C# concepts. This document is strictly intended to familiarize you with the basic world gen api.

VSTreasureChest

This mod places treasure chests around the world for the user to find. Each treasure chest has a random number of ingots in them. The mod only places treasure chests beside trees. It also adds a server command that can be run in the chat window called /treasure that places a treasure chest in front of the player. This can be useful for testing in case you want to change what items are in the chest and you don't want to bother looking for the chest for verification.


Getting started

Please follow the instructions here[2] for setting up your development environment. We named our project VSTreasureChest but you can choose any name you like. We will do one different thing. When you get to the debug command line arguments instead of passing /flatworld we are going to pass /stdworld:test. The reason we are doing this is because we are going to be placing our chest beside a tree. The /flatworld generates a flat world with no trees so that won't help us much in this scenario. However, depending on the specific terrain gen features you are doing you may want to use /flatworld in the future.

The /treasure command

First we are going to add the /treasure command. TODO:


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. TODO:


Finding where to place the chest

TODO


Excercises

A few things could be done to improve this code and it's left as an exercise for the reader. Doing this will help you get familiar with the API without overwhelming you.

  • Make chests a more rare item to find.
  • Currently the code will place chests over water or air. Change TryGetChestLocation to only place chests over solid blocks.
  • Chests should have more interesting items. Modify the code to put some more useful things in there. Maybe tools or weapons that can't be crafted.
  • A harder exercise might be to only place chests in caves.