Introduce gradle-plugin and mod-tools modules. Add ZomboidForge Gradle plugin for building, checking, and packaging mods. Include support for local test servers, automated game jar downloads, and mod descriptor generation. Add mod-tools for runtime mod checks and validations.
This commit is contained in:
1 parent
68cd9fc4f9
commit
063ad8a3e1
27 files changed
+1976
-30
No files matched your search
+109
-18
@@ -3,29 +3,119 @@
|
||||
How to write a server-side Java mod for ZomboidForge. Installing mods on a server is
|
||||
described in the [README](README.md#mods).
|
||||
|
||||
## Building
|
||||
## Project setup
|
||||
|
||||
A mod is a jar compiled against the `api` module (`./gradlew :api:jar`, then
|
||||
`api/build/libs/`). A mod that also uses game classes compiles against
|
||||
`projectzomboid.jar` and declares the game versions it supports.
|
||||
A mod is a normal Gradle project with the ZomboidForge plugin. It needs JDK 25 (Project
|
||||
Zomboid's runtime); the plugin sets the Java toolchain to 25.
|
||||
|
||||
## Descriptor
|
||||
`settings.gradle.kts`:
|
||||
|
||||
`META-INF/zomboidforge/mod.toml` in the jar:
|
||||
```kotlin
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven("https://git.security-command.org/api/packages/overlord/maven")
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
```toml
|
||||
id = "shop" # lowercase, digits, single underscores; the folder name
|
||||
name = "Shop"
|
||||
version = "1.2.0"
|
||||
entrypoint = "com.example.shop.ShopMod"
|
||||
api = "0.3" # ZomboidForge version the mod was built against
|
||||
game = ["42.21"] # only when the mod uses game classes: "42", "42.21", "42.21.0"
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
maven("https://git.security-command.org/api/packages/overlord/maven")
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
[dependencies]
|
||||
economy = "2.1" # mod id = minimum version; loaded first
|
||||
rootProject.name = "shop"
|
||||
```
|
||||
|
||||
Default settings go into `META-INF/zomboidforge/config.toml` in the jar.
|
||||
`build.gradle.kts`:
|
||||
|
||||
```kotlin
|
||||
plugins {
|
||||
id("dev.overlord.zomboidforge.mod") version "0.3.0" // the plugin's version is the API version
|
||||
}
|
||||
|
||||
version = "1.2.0"
|
||||
|
||||
zomboidForge {
|
||||
id = "shop"
|
||||
entrypoint = "com.example.shop.ShopMod"
|
||||
game("42.21") // only when the mod uses game classes
|
||||
dependsOn("economy", "2.1") // other mods: id and minimum version
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.google.code.gson:gson:2.11.0") // libraries go into the mod's lib/
|
||||
forgeMods("com.example:economy:2.1") // other mods to compile against
|
||||
}
|
||||
```
|
||||
|
||||
The plugin adds the API (`dev.overlord.zomboidforge:api`) as a compile-only dependency, and the
|
||||
game jar for mods that declare `game` versions. Default settings go into
|
||||
`src/main/resources/META-INF/zomboidforge/config.toml`.
|
||||
|
||||
### `zomboidForge { }`
|
||||
|
||||
| Setting | Default | Meaning |
|
||||
|--------------------------|------------------------------------------|-----------------------------------------------------------------------------------|
|
||||
| `id` | (required) | lowercase letters, digits, single underscores; at most 32 characters |
|
||||
| `entrypoint` | (required) | the class that extends `Mod` |
|
||||
| `name` | the id | display name |
|
||||
| `version` | the project version | the mod's version |
|
||||
| `api` | the plugin's version | ZomboidForge API version the mod is built against |
|
||||
| `game(...)` | none | supported Project Zomboid versions: `"42"`, `"42.21"`, `"42.21.0"` |
|
||||
| `dependsOn(id, version)` | none | another mod this one needs, with its minimum version |
|
||||
| `previousIds(...)` | none | earlier ids of the mod; their storage moves to the current id |
|
||||
| `gameJar` | see below | the `projectzomboid.jar` to compile and check against |
|
||||
| `steamBranch` | `public` | Steam branch for the download: `public`, `unstable`, or a version such as `42.19` |
|
||||
| `serverImage` | the ZomboidForge image, `latest` | image for `runServer` |
|
||||
| `adminPassword` | `admin` | admin password of the `runServer` server |
|
||||
| `dataVolume` | `zomboidforge-<id>` | volume for the `runServer` world and server config |
|
||||
| `containerEngine` | podman or docker, whichever is installed | for `runServer` and the download |
|
||||
| `deployDirectory` | none | a server's mods directory for `deployMod` |
|
||||
|
||||
The plugin generates `META-INF/zomboidforge/mod.toml` from these settings; a hand-written one
|
||||
fails the build.
|
||||
|
||||
### The game jar
|
||||
|
||||
Mods that declare `game` versions compile against `projectzomboid.jar`, which cannot be
|
||||
published. The plugin uses the first of:
|
||||
|
||||
1. `zomboidForge.gameJar`, or the Gradle property `zomboidforge.gameJar` (for example in
|
||||
`~/.gradle/gradle.properties`);
|
||||
2. a local Steam installation of the dedicated server or the game, in any Steam library;
|
||||
3. a download of the dedicated server with steamcmd (`steamcmd` if installed, otherwise its
|
||||
container image with podman or docker), once per Steam branch, into the Gradle user home.
|
||||
It is a few gigabytes.
|
||||
|
||||
The game jar has to be one of the declared `game` versions; the check below fails otherwise.
|
||||
|
||||
### Tasks
|
||||
|
||||
| Task | Does |
|
||||
|----------------|---------------------------------------------------------------------------------------------|
|
||||
| `build` | compiles, runs `checkMod`, and assembles the mod |
|
||||
| `checkMod` | the server's load checks, at build time (see [Checks at startup](#checks-at-startup)) |
|
||||
| `modFolder` | `build/mod/<id>/` with `<id>.jar` and `lib/`, as a server expects it in `<forge>/mods` |
|
||||
| `modZip` | the same as `build/distributions/<id>-<version>.zip` |
|
||||
| `runServer` | a ZomboidForge server in a container with the mod; Ctrl+C stops it after it saved the world |
|
||||
| `deployMod` | copies the mod folder into `deployDirectory` |
|
||||
| `downloadGame` | installs the dedicated server for its game jar; runs only when needed |
|
||||
|
||||
### Working on ZomboidForge itself
|
||||
|
||||
To build a mod against a local ZomboidForge checkout instead of a published version, include it
|
||||
in `settings.gradle.kts`; Gradle then builds the plugin, the API, and the mod tools from the
|
||||
checkout:
|
||||
|
||||
```kotlin
|
||||
pluginManagement {
|
||||
includeBuild("../ZomboidForge")
|
||||
}
|
||||
|
||||
includeBuild("../ZomboidForge")
|
||||
```
|
||||
|
||||
## Entry point
|
||||
|
||||
@@ -170,8 +260,9 @@ Things to know:
|
||||
|
||||
## Checks at startup
|
||||
|
||||
Before any mod code runs, ZomboidForge reads every class of the mod and its libraries. The
|
||||
server does not start when a mod
|
||||
`checkMod` runs these checks when the mod is built, so a mod that would not load fails its
|
||||
build instead. On the server, before any mod code runs, ZomboidForge reads every class of the
|
||||
mod and its libraries. The server does not start when a mod
|
||||
|
||||
1. uses game classes without declaring `game` versions in `mod.toml`,
|
||||
2. uses a game class, field, or method that does not exist in the running version,
|
||||
|
||||
Reference in new issue
Block a user