Class Mod

java.lang.Object
dev.overlord.zomboidforge.api.Mod

public abstract class Mod extends Object
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:

  1. onLoad(): registration and setup. The server database, Lua, and the world do not exist yet.
  2. onServerStarted(): the world is loaded and the network port is open.
  3. onStopping(): the server stops; the world has not been saved yet.
An exception thrown by the constructor or onLoad() stops the server.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Mod()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final AsyncExecutor
    Virtual threads for blocking work such as HTTP calls or file I/O.
    protected final ClientCommands
    Server commands to clients, received by their Lua mods.
    protected final Commands
    Admin command registration.
    protected final ModConfig
    The mod's settings from config.toml.
    protected final Path
    The mod's folder, <forge>/mods/<id>.
    protected final Events
    Event listener registration.
    protected final GameVersion
    The running Project Zomboid version.
    final String
    id()
    The id from mod.toml.
    protected final System.Logger
    Logger whose messages go into the Project Zomboid log, marked with the mod's id.
    protected final MainThread
    The server's main thread, for everything that touches game objects.
    protected final ModThread
    The mod's own platform thread, zf-mod-<id>: one task at a time, in order.
    void
    Called once on the main thread, after the instance is created.
    void
    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.
    void
    Called once on the shutdown thread when the server stops, before the world is saved.
    protected final ModStorage
    The mod's tables in the world's zomboidforge.db; not on the main thread once the server runs.
    final String
    The version from mod.toml.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • id

      public final String id()
      The id from mod.toml.
    • version

      public final String version()
      The version from mod.toml.
    • onLoad

      public void onLoad() throws Exception
      Called once on the main thread, after the instance is created.
      Throws:
      Exception
    • onServerStarted

      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

      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

      protected final GameVersion gameVersion()
      The running Project Zomboid version.
    • logger

      protected final System.Logger logger()
      Logger whose messages go into the Project Zomboid log, marked with the mod's id.
    • directory

      protected final Path directory()
      The mod's folder, <forge>/mods/<id>.
    • config

      protected final ModConfig config()
      The mod's settings from config.toml.
    • events

      protected final Events events()
      Event listener registration.
    • main

      protected final MainThread main()
      The server's main thread, for everything that touches game objects.
    • modThread

      protected final ModThread modThread()
      The mod's own platform thread, zf-mod-<id>: one task at a time, in order.
    • async

      protected final AsyncExecutor async()
      Virtual threads for blocking work such as HTTP calls or file I/O.
    • storage

      protected final ModStorage storage()
      The mod's tables in the world's zomboidforge.db; not on the main thread once the server runs.
    • commands

      protected final Commands commands()
      Admin command registration.
    • clientCommands

      protected final ClientCommands clientCommands()
      Server commands to clients, received by their Lua mods.