Class Mod
java.lang.Object
dev.overlord.zomboidforge.api.Mod
Base class of every mod. The class named as
entrypoint in mod.toml extends it
and has a public constructor without parameters.
ZomboidForge creates one instance per mod on the main thread, in dependency order, while the server starts. The methods of this class work from the constructor on, so field initializers may use them.
Lifecycle, in this order:
- Listener methods: the methods annotated with
OnMain,OnModThread,OnClientCommand, orEveryNTicksare registered (seeEvents.register(Object)). onLoad(): registration and setup. The server database, Lua, and the world do not exist yet.onServerStarted(): the world is loaded and the network port is open. Once it returned, the methods annotated withEverystart.onStopping(): the server stops; the world has not been saved yet.
onLoad(), or a listener method that breaks
the rules, stops the server.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final AsyncExecutorasync()Virtual threads for blocking work such as HTTP calls or file I/O.protected final ClientCommandsServer commands to clients, received by their Lua mods.protected final Commandscommands()Admin command registration.protected final ModConfigconfig()The mod's settings fromconfig.toml.protected final PathThe mod's folder,<forge>/mods/<id>.protected final Eventsevents()Event listener registration.protected final GameVersionThe running Project Zomboid version.final Stringid()The id frommod.toml.protected final System.Loggerlogger()Logger whose messages go into the Project Zomboid log, marked with the mod's id.protected final MainThreadmain()The server's main thread, for everything that touches game objects.protected final ModThreadThe mod's own platform thread,zf-mod-<id>: one task at a time, in order.voidonLoad()Called once on the main thread, after the instance is created.voidCalled once on the main thread, after the world is loaded, the network port is open, and RCON is initialized; directly before the main loop starts.voidCalled once on the shutdown thread when the server stops, before the world is saved.protected final ModStoragestorage()The mod's tables in the world'szomboidforge.db; not on the main thread once the server runs.final Stringversion()The version frommod.toml.
-
Constructor Details
-
Mod
protected Mod()- Throws:
IllegalStateException- when the instance is not created by ZomboidForge
-
-
Method Details
-
id
The id frommod.toml. -
version
The version frommod.toml. -
onLoad
-
onServerStarted
@OverrideOnly @NonBlocking public void onServerStarted()Called once on the main thread, after the world is loaded, the network port is open, and RCON is initialized; directly before the main loop starts. -
onStopping
@OverrideOnly public void onStopping()Called once on the shutdown thread when the server stops, before the world is saved. The main thread may still be finishing a tick. Mods are stopped in reverse load order. -
gameVersion
The running Project Zomboid version. -
logger
Logger whose messages go into the Project Zomboid log, marked with the mod's id. -
directory
The mod's folder,<forge>/mods/<id>. -
config
The mod's settings fromconfig.toml. -
events
Event listener registration. -
main
The server's main thread, for everything that touches game objects. -
modThread
The mod's own platform thread,zf-mod-<id>: one task at a time, in order. -
async
Virtual threads for blocking work such as HTTP calls or file I/O. -
storage
The mod's tables in the world'szomboidforge.db; not on the main thread once the server runs. -
commands
Admin command registration. -
clientCommands
Server commands to clients, received by their Lua mods.
-