Shared state between client and server

This commit is contained in:
2026-10-03 18:45:07 -03:00
parent 63e6248f9f
commit 7417bfd5f1
24 changed files with 656 additions and 193 deletions
+8 -5
View File
@@ -1,6 +1,6 @@
# Mod Files
A mod is a folder with a `manifest.json`, some data files, textures, and up to three scripts. The build packs it into a
A mod is a folder with a `manifest.json`, some data files, textures, and up to four scripts. The build packs it into a
single `.bmod` file, which is what servers load.
## Layout
@@ -25,6 +25,7 @@ mods/
scripts/
server.ts # game logic, never sent to players
client.ts # sent to players
shared.ts # block rules, run on the server and sent to players
worldgen.ts # terrain features, never sent to players
```
@@ -55,7 +56,8 @@ matter, the `id` inside does, except for [tags](../resources/tags.md), whose id
"scripts": {
"server": "scripts/server.ts",
"client": "scripts/client.ts",
"worldgen": "scripts/worldgen.ts"
"worldgen": "scripts/worldgen.ts",
"shared": "scripts/shared.ts"
},
"credits": "CREDITS.md"
}
@@ -71,7 +73,7 @@ matter, the `id` inside does, except for [tags](../resources/tags.md), whose id
| `authors` | no | A list of names. |
| `game_version` | no | The bworld versions the mod works with, as a semver range. Not checked yet. |
| `dependencies` | no | Other mods, `{ "id", "version" }`. A missing dependency is an error, and dependencies load first. The version range isn't checked yet. |
| `scripts` | no | Paths to the `server`, `client` and `worldgen` scripts. See [Sides](../concepts/sides.md). |
| `scripts` | no | Paths to the `server`, `client`, `shared` and `worldgen` scripts. 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
@@ -90,8 +92,8 @@ so they can import other files and packages, but code imported by several script
When a mod's folder has a `deno.json`, its scripts are 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 scripts import as `bworld/server`, `bworld/client` and
`bworld/worldgen`:
this repository. That config maps the API types, which scripts import as `bworld/server`, `bworld/client`,
`bworld/shared` and `bworld/worldgen`:
```ts
import type { ServerContext } from "bworld/server";
@@ -114,6 +116,7 @@ copper_tools.bmod
scripts/server.js # each script bundled into one module
scripts/client.js
scripts/worldgen.js
scripts/shared.js
textures/<name>.png
credits.md
```