Modding:Code Tutorial Essentials: Difference between revisions

From Vintage Story Wiki
Line 6: Line 6:


== Modding Tutorials ==
== Modding Tutorials ==
All tutorials within the categorized sections (basic, intermediate, advanced, other) can be made in the same project as one another. All tutorials are created under the project name "VSTutorial". It is recommended to [[Modding:Creating A Code Mod|create a new mod]] with the same project name, and use this project when you wish to complete any tutorial.  
All tutorials within the categorized sections (basic, intermediate, advanced, other) can be made in the same project as one another, as they are all created under the project name "VSTutorial". '''It is recommended to [[Modding:Creating A Code Mod|create a new mod]] with the same project name, and use this project when you wish to complete any of these tutorials.'''


When writing code, it's important to keep your code well-organized and documented. Coding styles vary from person to person, however the tutorials will always prefer readability and understandability over efficiency. If there are instances of more efficient code, these may be mentioned at the time.
When writing code, it's important to keep your code well-organized and documented. Coding styles vary from person to person, however the tutorials will always prefer readability and understandability over efficiency. If there are instances of more efficient code, these may be mentioned at the time.


== Client/Server ==
== Client/Server ==
Vintage Story loads all worlds by using a client/server system. There always exists one server per world, however there can be any number of clients. Each player that joins the world, including a singleplayer world, is classed as a client.  
Vintage Story loads all worlds by using a '''client/server system'''. There always exists one server per world, however there can be any number of clients. Each player that joins the world, including a singleplayer world, is classed as a client.  


Many aspects of code are split between the server and the client. In general, the client is used for rendering, inputs, and more precise physics calculations. The server determines world logic, most entity logic, and communication between all clients.  
Many aspects of code are split between the server and the client. In general, the client is used for rendering, inputs, and more precise physics calculations. The server determines world logic, most entity logic, and communication between all clients.  
Line 24: Line 24:
Some useful functions that your mod system can use are:
Some useful functions that your mod system can use are:


* Start - This is called on both the server and the client, and is where you should register blocks, items, entities, and most other things that need registering.
* '''Start''' - This is called on both the server and the client, and is where you should register blocks, items, entities, and most other things that need registering.
* StartServerSide - This is called only on the server side. You should register any server-side-only classes and logic here. Most commands will be registered here.
* '''StartServerSide''' - This is called only on the server side. You should register any server-side-only classes and logic here. Most commands will be registered here.
* StartClientSide - Similarly to StartServerSide, but only called on the client side. You should use this to register and rendering or UI logic here.
* '''StartClientSide''' - Similarly to StartServerSide, but only called on the client side. You should use this to register and rendering or UI logic here.
* ShouldLoad - This can be used to control what side your mod should be loaded on. You can use this to make client-only or server-only mods.
* '''ShouldLoad''' - This can be used to control what side your mod should be loaded on. You can use this to make client-only or server-only mods.
* ExecuteOrder - This is an extremely important function that alters when your mod is loaded. Check the GitHub link below for information on what is loaded in what order.
* '''ExecuteOrder''' - This is an extremely important function that alters when your mod is loaded. Check the GitHub link below for information on what is loaded in what order.
There are many other functions that are more specific. You can view [https://github.com/anegostudios/vsapi/blob/cad83424ee89915ef206d0b23845af0a4ef72348/Common/API/ModSystem.cs#L12 Mod System on GitHub] for a full breakdown of this class.
There are many other functions that are more specific. You can view [https://github.com/anegostudios/vsapi/blob/cad83424ee89915ef206d0b23845af0a4ef72348/Common/API/ModSystem.cs#L12 Mod System on GitHub] for a full breakdown of this class.


== CoreAPI, CoreServerAPI, CoreClientAPI ==
== CoreAPI, CoreServerAPI, CoreClientAPI ==
The CoreAPI class is extremely important, and is used throughout many different aspects of the game. The CoreServerAPI and CoreClientAPI are specific instances of CoreAPIs for server and client logic respectively.
The '''CoreAPI''' class is extremely important, and is used throughout many different aspects of the game. The CoreServerAPI and CoreClientAPI are specific instances of CoreAPIs for server and client logic respectively.


The CoreAPI is used to handle assets, commands, events, registries, world data, and many other things.
The CoreAPI is used to handle assets, commands, events, registries, world data, and many other things.  


You can find the following classes on GitHub.
You can find the following classes on GitHub.