Modding:WorldGen API: Difference between revisions

From Vintage Story Wiki
no edit summary
No edit summary
(3 intermediate revisions by 3 users not shown)
Line 2: Line 2:
== Intro ==
== Intro ==


We will be walking through how to 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 [https://github.com/anegostudios/VSTreasureChest here]. 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.
We will be walking through how to plug in and add your own features to the world generation code of Vintage Story by looking at a demo mod called VSTreasureChest. The full source code for this project can be found [https://github.com/anegostudios/VSTreasureChest on Github]. We are going to walk through coding it from scratch.


== VSTreasureChest Mod==
== VSTreasureChest Mod==
Line 10: Line 10:


== Getting started ==
== Getting started ==
Please follow the instructions here[http://wiki.vintagestory.at/index.php?title=Setting_up_a_dev_environment] 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.
Please follow the instructions [[Setting up your Development Environment|here]] 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.




Line 25: Line 25:
namespace Vintagestory.Mods.TreasureChest
namespace Vintagestory.Mods.TreasureChest
{
{
     public class VSTreasureChestMod : ModBase
     public class VSTreasureChestMod : ModSystem
     {
     {
         private ICoreServerAPI api;
         private ICoreServerAPI api;
Line 42: Line 42:
</syntaxhighlight>
</syntaxhighlight>


The first thing to note is the '''using''' directives at the top. Those that start with Vintagestory will allow us to access classes in the Vintagestory api. Next the '''StartServerSide''' is a method we are overriding from '''ModBase''' that is called once when the server is start up. Here we start by just storing a reference to the '''ICoreServerAPI''' for convenient access later. We will also be registering call backs for other events here. We also override '''ShouldLoad''' to tell the system to only load this on the server side and not the client side. It would work without this but it's not necessary for the client to load this mod since all our code happens server side.
The first thing to note is the '''using''' directives at the top. Those that start with Vintagestory will allow us to access classes in the Vintagestory api. Next the '''StartServerSide''' is a method we are overriding from '''ModSystem''' that is called once when the server is start up. Here we start by just storing a reference to the '''ICoreServerAPI''' for convenient access later. We will also be registering call backs for other events here. We also override '''ShouldLoad''' to tell the system to only load this on the server side and not the client side. It would work without this but it's not necessary for the client to load this mod since all our code happens server side.


== The /treasure command ==
== The /treasure command ==
Line 430: Line 430:
<li>A harder exercise might be to only place chests in caves.</li>
<li>A harder exercise might be to only place chests in caves.</li>
</ul>
</ul>
{{Navbox/modding|Vintage Story}}
Confirmedusers, editor, Administrators
886

edits