Modding:Moddable Mod: Difference between revisions

From Vintage Story Wiki
m
no edit summary
mNo edit summary
Line 117: Line 117:
Our resulting folder structure looks like this.
Our resulting folder structure looks like this.
[[File:ModdableModFolderStructure.png|none]]
[[File:ModdableModFolderStructure.png|none]]
We are now ready to start adding the functionality of our mods, starting with "TipMod", as that will be our
We are now ready to extend our mods, starting with "TipMod" - our moddable mod.
point of interaction.


== Setting up TipMod ==
== Setting up TipMod ==
For "TipMod", we do the following.
For "TipMod", we do the following:
* Store the <code>ICoreServerAPI</code> object as a field so that we can access it throughout our class.
* Store the <code>ICoreServerAPI</code> object as a field so that we can access it throughout our class.
* Define a <code>List</code> that stores <code>Tip</code> objects.
* Define a <code>List</code> that stores <code>Tip</code> objects.
Line 177: Line 176:
In C#, classes and methods are not public by default. You can [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers read more about this here.]
In C#, classes and methods are not public by default. You can [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers read more about this here.]


We can now compile our mod, add it to our VintageStory mod folder and test it ingame. If the there are occasional chat messages
We can now compile our mod, add it to our VintageStory mod folder and test it ingame. If the there are occasional chat messages saying "There aren't any listed tips", our mod is working. We are ready to move on to the next step - setting up "SpawnMod" and then having it interact with "TipMod".
claiming that no tips are listed, our mod is working. We are ready to move on to the next step - setting up "SpawnMod" and then having it interact with "TipMod".
== Setting up SpawnMod ==
== Setting up SpawnMod ==
Let's first setup our mods functionality. We register a command which teleports the player to spawn. Conveniently, the [http://apidocs.vintagestory.at/api/Vintagestory.API.Server.IServerPlayer.html IServerPlayer] object stores it's spawn position, as well as the [http://apidocs.vintagestory.at/api/Vintagestory.API.Common.IPlayer.html#Vintagestory_API_Common_IPlayer_Entity IPlayerEntity], which defines a method for teleporting itself to a location.  
Let's first setup our mods functionality. We register a command which teleports the player to spawn. Conveniently, the [http://apidocs.vintagestory.at/api/Vintagestory.API.Server.IServerPlayer.html <code>IServerPlayer</code>] object stores it's spawn position, as well as the [http://apidocs.vintagestory.at/api/Vintagestory.API.Common.IPlayer.html#Vintagestory_API_Common_IPlayer_Entity <code>IPlayerEntity</code>], which defines a method for teleporting itself to a location.  
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
    // In SpawnMod.cs
     class SpawnMod : ModSystem
     class SpawnMod : ModSystem
     {
     {
Line 377: Line 376:


Here are the official versions:
Here are the official versions:
* for VS v1.13.2: [https://wiki.vintagestory.at/index.php?title=File:TipMod_vs1.13.2_v1.0.0.zip File:TipMod_vs1.13.2_v1.0.0.zip] and [https://wiki.vintagestory.at/index.php?title=File:SpawnMod_vs1.13.2_v1.0.0.zip File:SpawnMod_vs1.13.2_v1.0.0.zip].
* for VS v1.13.2: [https://wiki.vintagestory.at/index.php?title=File:TipMod_vs1.13.2_v1.0.0.zip TipMod_vs1.13.2_v1.0.0.zip] and [https://wiki.vintagestory.at/index.php?title=File:SpawnMod_vs1.13.2_v1.0.0.zip SpawnMod_vs1.13.2_v1.0.0.zip].


{{Navbox/modding|Vintage Story}}
{{Navbox/modding|Vintage Story}}