Class ModSystem
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
Base of a system, which is part of a code mod. Takes care of setting up, registering and handling all sorts of things. You may choose to split up a mod into multiple distinct systems if you so choose, but there may also be just one.
public abstract class ModSystem
- Inheritance
-
ModSystem
- Inherited Members
- Extension Methods
Properties
Mod
Gets the Mod this mod system is part of.
public Mod Mod { get; }
Property Value
Methods
AssetsFinalize(ICoreAPI)
When called on a server, all Block.OnLoaded() methods etc. have already been called, this is for any final asset set-up steps to be done after that. See VSSurvivalMod system BlockReinforcement.cs for an example.
public virtual void AssetsFinalize(ICoreAPI api)
Parameters
api
ICoreAPI
AssetsLoaded(ICoreAPI)
Called on the server or the client; implementing code may need to check which side it is.
On a server, called only after all mods have received Start(), and after asset JSONs have been read from disk and patched, but before runphase ModsAndConfigReady.
Asset files are now available to load using api.Assets.TryGet() calls or similar. If your execute order is below 0.2, blocks and items are not yet registered at this point, if below 0.6 recipes are not yet registered.
public virtual void AssetsLoaded(ICoreAPI api)
Parameters
api
ICoreAPI
Dispose()
If this mod allows runtime reloading, you must implement this method to unregister any listeners / handlers
public virtual void Dispose()
ExecuteOrder()
If you need mods to be executed in a certain order, adjust this methods return value.
The server will call each Mods StartPre() and Start() methods in ascending order of each mods execute order value. And thus, as long as every mod registers it's event handlers in the Start() method, all event handlers will be called in the same execution order.
Default execute order of some survival mod parts
Worldgen:
- GenTerra: 0
- RockStrata: 0.1
- Deposits: 0.2
- Caves: 0.3
- Blocklayers: 0.4
AssetsLoaded event - JsonPatch loader: 0.05
- Load hardcoded mantle block: 0.1
- Block and Item Loader: 0.2
- Recipes (Smithing, Knapping, Clayforming, Grid recipes, Alloys) Loader: 1
public virtual double ExecuteOrder()
Returns
ShouldLoad(EnumAppSide)
Returns if this mod should be loaded for the given app side, called by ShouldLoad(ICoreApi api)
public virtual bool ShouldLoad(EnumAppSide forSide)
Parameters
forSide
EnumAppSide
Returns
ShouldLoad(ICoreAPI)
Returns if this mod should be loaded for the given app side.
public virtual bool ShouldLoad(ICoreAPI api)
Parameters
api
ICoreAPI
Returns
Start(ICoreAPI)
Start method, called on both server and client after all mods already received a call to StartPre(), but before Blocks/Items/Entities/Recipes etc are loaded and some time before StartServerSide / StartClientSide.
Typically used to register for events and network packets etc
Typically also used in a mod's core to register the classes for your blocks, items, entities, blockentities, behaviors etc, prior to loading assets
Do not make calls to api.Assets at this stage, the assets may not be found, resulting in errors (even if the json file exists on disk). Use AssetsLoaded() stage instead.
public virtual void Start(ICoreAPI api)
Parameters
api
ICoreAPI
StartClientSide(ICoreClientAPI)
Full start to the mod on the client side.
Note, in multiplayer games, the server assets (blocks, items, entities, recipes) have not yet been received and so no blocks etc. are yet registered
For code that must run only after we have blocks, items, entities and recipes all registered and loaded, add your method to event BlockTexturesLoaded
public virtual void StartClientSide(ICoreClientAPI api)
Parameters
api
ICoreClientAPI
StartPre(ICoreAPI)
Called during intial mod loading, called before any mod receives the call to Start()
public virtual void StartPre(ICoreAPI api)
Parameters
api
ICoreAPI
StartServerSide(ICoreServerAPI)
Full start to the mod on the server side
Note: preferably, your code which adds or updates behaviors or attributes or other fixed properties of any block, item or entity, should have been run before now.
For example, code which needs to do that could be placed in an overridden AssetsFinalize() method. See VSSurvivalMod system BlockReinforcement.cs for an example.
public virtual void StartServerSide(ICoreServerAPI api)
Parameters
api
ICoreServerAPI