Modding:Code Tutorial Essentials: Difference between revisions

From Vintage Story Wiki
(Page creation. In progress.)
 
mNo edit summary
Line 6: Line 6:
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,  
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.
 
Clients cannot directly communicate with other clients. In order to share data, the server must send this to appropriate clients.


== Mod System ==
== Mod System ==
Line 15: Line 17:
Some useful functions that your mod system can use are:
Some useful functions that your mod system can use are:


* Start -  
* 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.
* 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.
* 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.
 
== 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 is used to handle assets, commands, events, registries, world data, and many other things.
 
You can find the following classes on GitHub.


([https://github.com/anegostudios/vsapi/blob/cad83424ee89915ef206d0b23845af0a4ef72348/Common/API/ModSystem.cs#L12 Mod System on GitHub])
* [https://github.com/anegostudios/vsapi/blob/cad83424ee89915ef206d0b23845af0a4ef72348/Common/API/ICoreAPI.cs#L20 ICoreAPICommon] - A set of functions and fields common to the server and client.
* [https://github.com/anegostudios/vsapi/blob/cad83424ee89915ef206d0b23845af0a4ef72348/Common/API/ICoreAPI.cs#L20 ICoreAPI] - Extends from ICoreAPICommon, contains a few more useful values.
* [https://github.com/anegostudios/vsapi/blob/cad83424ee89915ef206d0b23845af0a4ef72348/Client/API/ICoreClientAPI.cs#L10 ICoreClientAPI] - Extends from ICoreAPI. Contains useful functions and fields that can be used only on the client-side.
* [https://github.com/anegostudios/vsapi/blob/cad83424ee89915ef206d0b23845af0a4ef72348/Server/API/ICoreServerAPI.cs#L9 ICoreServerAPI] - Extends from ICoreAPI. Contains useful functions and fields that can be used only on the server-side.

Revision as of 21:45, 24 May 2024

This page will give a breakdown of a number of topics and terminology used with code modding. Since some code topics can become quite complex, it is important to read through this page.

This page will also introduce you to the coding tutorials and how they work.

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.

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.

Clients cannot directly communicate with other clients. In order to share data, the server must send this to appropriate clients.

Mod System

A Mod System is used entry point for your mod, and contains many useful functions for the execution of your mod. A single mod can have multiple mod systems, but must have at least one for any code to be executed.

When creating a mod using the mod template, you will notice that a mod system is automatically generated with a number of functions.

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.
  • 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.
  • 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.

There are many other functions that are more specific. You can view Mod System on GitHub for a full breakdown of this class.

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 is used to handle assets, commands, events, registries, world data, and many other things.

You can find the following classes on GitHub.

  • ICoreAPICommon - A set of functions and fields common to the server and client.
  • ICoreAPI - Extends from ICoreAPICommon, contains a few more useful values.
  • ICoreClientAPI - Extends from ICoreAPI. Contains useful functions and fields that can be used only on the client-side.
  • ICoreServerAPI - Extends from ICoreAPI. Contains useful functions and fields that can be used only on the server-side.