132 lines
7.0 KiB
Markdown
132 lines
7.0 KiB
Markdown
# Mod Files
|
|
|
|
A mod is a folder with a `manifest.json`, some data files, textures, and a script. The build packs it into a single
|
|
`.cubi` file, which is what servers load.
|
|
|
|
## Layout
|
|
|
|
```
|
|
mods/
|
|
copper_tools/
|
|
manifest.json # required, everything else is optional
|
|
deno.json # makes the mod its own deno project, see below
|
|
CREDITS.md # shown on the Credits screen
|
|
config.json # settings servers can change, never sent to players. see misc/config.md
|
|
blocks/*.json # one block per file
|
|
items/*.json # items that aren't a block's item form
|
|
models/*.json # block models
|
|
models/*.geo.json # entity models
|
|
entities/*.json
|
|
effects/*.json # status effects, see entities/effects.md
|
|
fluids/*.json # fluids that can be held, see resources/fluids.md
|
|
recipes/*.json
|
|
tags/<registry>/<namespace>/*.json # tags, see resources/tags.md
|
|
loot_tables/**/*.json # loot tables, see resources/loot_tables.md
|
|
worldgen/ores.json
|
|
worldgen/biomes/*.json # one biome per file, see worldgen/biomes.md
|
|
worldgen/noise/**/*.json # the terrain as data, never sent to players. see worldgen/terrain.md
|
|
worldgen/density_function/**/*.json
|
|
worldgen/noise_settings/**/*.json
|
|
worldgen/biome_source/**/*.json
|
|
worldgen/spawns.json # monsters that spawn on their own, see entities/index.md
|
|
textures/*.png
|
|
textures/*.json # animations, see resources/textures.md
|
|
scripts/
|
|
main.ts # the mod's script, its exports are its phases. sent to players, see concepts/sides.md
|
|
*.ts # whatever else it imports
|
|
```
|
|
|
|
Data folders can have subfolders. Every data file holds one definition, wrapped with the format version:
|
|
|
|
```json
|
|
{
|
|
"format_version": 1,
|
|
"block": { "id": "copper_tools:copper_block", "textures": "copper_tools:copper_block" }
|
|
}
|
|
```
|
|
|
|
The key is `block`, `item`, `model`, `entity`, `effect`, `recipe` or `tag`, depending on the folder. File names don't
|
|
matter, the `id` inside does, except for [tags](../resources/tags.md), whose id is their path.
|
|
|
|
## `manifest.json`
|
|
|
|
```json
|
|
{
|
|
"format_version": 1,
|
|
"id": "copper_tools",
|
|
"name": "Copper Tools",
|
|
"description": "Copper blocks and a copper pickaxe.",
|
|
"version": "1.0.0",
|
|
"authors": ["paula"],
|
|
"game_version": ">=0.1.0",
|
|
"dependencies": [{ "id": "bworld", "version": "*" }],
|
|
"main": "scripts/main.ts",
|
|
"credits": "CREDITS.md"
|
|
}
|
|
```
|
|
|
|
| Field | Required | Meaning |
|
|
| ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
| `format_version` | yes | Always `1`. Loaders reject versions they don't know. |
|
|
| `id` | yes | The mod's [namespace](../concepts/registries.md#identifiers). 1-32 characters of `a-z`, `0-9` and `_`, matching the folder name. |
|
|
| `name` | yes | Display name, shown to players when they join from another site and on the Credits screen. |
|
|
| `description` | no | A sentence or two. |
|
|
| `version` | yes | The mod's own version, semver like `1.0.0`. |
|
|
| `authors` | no | A list of names. |
|
|
| `game_version` | no | The bworld versions the mod works with, as a semver range. Only checked for mods with `engine_access`. |
|
|
| `engine_access` | no | `true` lets the script import `cubi/engine` and hook the engine. See [Engine Access](../misc/engine.md). |
|
|
| `dependencies` | no | Other mods, `{ "id", "version" }`. A missing dependency is an error, and dependencies load first. The version range isn't checked yet. |
|
|
| `main` | no | The path of the mod's script, whose exports are its phases. See [Sides](../concepts/sides.md). |
|
|
| `credits` | no | A markdown file for licenses and thanks, shown on the Credits screen. Raw HTML in it is shown as text. |
|
|
|
|
List every mod whose ids you use in `dependencies`, including `bworld` for the base game's blocks and items. It
|
|
guarantees they're loaded before yours, and `check-mods` warns when one is missing.
|
|
|
|
## The Script
|
|
|
|
A mod's script is an ES module whose exports are its phases: `content`, `shared`, `server`, `client` and `worldgen`,
|
|
each a function called with its context where and when it runs. See [Sides](../concepts/sides.md). The build bundles it
|
|
with everything it imports into one module, so it can import other files and packages.
|
|
|
|
> [!WARNING]
|
|
> The whole script is sent to every player who joins, its server phase too. Don't put secrets in it.
|
|
|
|
### Mods as Deno Projects
|
|
|
|
When a mod's folder has a `deno.json`, its script is bundled and typechecked with it, so the mod can have its own
|
|
imports and npm or JSR packages. Mods without one use the `deno.json` of the folder the build runs in, like the mods in
|
|
this repository. That config maps the API types, which the script imports as `cubi/server`, `cubi/client`,
|
|
`cubi/shared`, `cubi/worldgen` and `cubi/content`, and [`cubi/engine`](../misc/engine.md):
|
|
|
|
```ts
|
|
import type { ServerContext } from "cubi/server";
|
|
```
|
|
|
|
## `.cubi` Files
|
|
|
|
A `.cubi` is a built mod in one zip file. Servers load every `.cubi` in their `server_mods/` folder, so installing a mod
|
|
on a server is dropping its file there and restarting.
|
|
|
|
```sh
|
|
deno task pack-mod mods/copper_tools # writes copper_tools.cubi, to share
|
|
deno task build # packs every mod in mods/ into server_mods/
|
|
```
|
|
|
|
```
|
|
copper_tools.cubi
|
|
manifest.json # with main and credits pointing into the zip
|
|
data.json # every block, model, item, entity, recipe, ore, tag and loot table, and the config
|
|
script.js # the script bundled into one module
|
|
textures/<name>.png
|
|
textures/<name>.json # for animated textures
|
|
credits.md
|
|
```
|
|
|
|
- Packing checks the mod first, like `check-mods`, and refuses one with errors.
|
|
- Packing the same mod twice gives the same bytes, so the file only changes when the mod does.
|
|
- `deno task build` leaves other `.cubi` files in `server_mods/` alone, so mods from elsewhere can sit next to the ones
|
|
it builds.
|
|
- `data.json` doesn't hold the blocks the content phase registers. The server runs it when it loads the `.cubi`.
|
|
- Players get a copy **without** the terrain's data and the config, but with the blocks the content phase registered in
|
|
its `data.json`. See [Networking](../networking/index.md).
|