4.9 KiB
Getting Started
This section covers making a new mod, checking it, and running it on a local server.
Prerequisites
- Familiarity with TypeScript (or JavaScript). Scripts can be
.tsor.js, and the mod API is typed. - Deno. Every tool in this repository runs through
deno task. - A clone of the bworld repository. Mods live in its
mods/folder while you work on them.
bworld is always played on a server, with no single player mode. A mod is installed on the server only. Players who join download its client code, data and textures from that server automatically, so they never install anything themselves.
Creating a Mod
deno task new-mod copper_tools "Copper Tools"
This copies templates/mod to mods/copper_tools and fills in the id and name. The template has one of everything: a
block with a custom component, an item, a shaped recipe, two textures, and a server, client and worldgen script. Delete
what you don't need, along with its entry in manifest.json.
The first argument is the mod's id, its namespace. It has to match the folder name.
Tip
The mods already in the repository are the best reference.
mods/bworldis the base game itself, written against the same API as any other mod.mods/createsadds a lot of blocks and mechanics, andmods/recipe_vieweris a client-only mod with an inventory overlay and a screen of its own.
Checking Your Mod
deno task check-mods
This checks every mod in mods/:
- the manifest and every data file, against the formats in these docs,
- that every block, item, model and entity model a mod refers to exists,
- that textures exist (a missing one is a warning, since it shows as the missing texture instead of failing),
- that a mod lists the mods whose ids it uses in its
dependencies(a warning), - that ids are in the mod's own namespace, and that no two mods register the same id,
- that the scripts typecheck against the API types.
Folders in mods/ starting with _ or . are skipped, which is handy for parking a mod you aren't working on.
Building and Running
deno task build # packs every mod in mods/ into server_mods/<id>.bmod, and builds the client
deno task server # starts a server with every .bmod in server_mods/
build refuses to pack a mod that has errors. The server checks every .bmod again when it starts, and a problem in
any mod stops it from starting, naming the mod and what's wrong. The game never runs with some mods missing.
Open the server's address in a browser to play. To try a change, rebuild and restart the server, then rejoin. Leaving a server reloads the page, so no old mod code stays loaded.
Useful Commands In Game
| Command | What it does |
|---|---|
/give <item> [count] |
Gives you an item, see Commands for data |
/summon <entity> |
Spawns an entity where you stand |
/time set <when> |
Jumps to day, noon, sunset, night or midnight |
/time add <ticks> |
Moves time forward, running every morning it passes |
/help |
Lists every command |
See Commands for the rest, and for adding your own.
Testing
deno task test runs the repository's tests. tests/helpers.ts has test_game, which starts a real game server with
the mods in a folder and lets a test join as a player and send what a client would:
import { assertEquals } from "@std/assert";
import { test_game } from "./helpers.ts";
Deno.test("a hoe turns grass into farmland", async () => {
const { game, join, send, take } = await test_game("mods");
join(1, "alice");
game.set_block(1, 100, 1, "bworld:grass");
send(1, { type: "move", x: 2.5, y: 101, z: 2.5, yaw: 0, pitch: 0 });
send(1, { type: "chat", text: "/give bworld:wood_hoe" });
const inventory = take(1).filter((m) => m.type === "container" && m.container === "inventory").at(-1).items;
send(1, {
type: "select_slot",
slot: inventory.findIndex((i: { id: string } | null) => i?.id === "bworld:wood_hoe"),
});
send(1, { type: "use_block", x: 1, y: 100, z: 1, face: "top" });
assertEquals(game.world.get_block_id(1, 100, 1), "bworld:hoed_dirt");
});
tests/farming_test.ts, tests/cooking_test.ts and tests/cutting_board_test.ts test mods this way.