Files
bworld/CLAUDE.md
T
2026-11-03 17:17:37 -03:00

4.7 KiB

bworld

A voxel game in TypeScript on Deno. The base game is itself a mod (mods/bworld), written against the same modding API as any other mod.

Never under any circumstance commit anything on your own

Never under any circumstance generate any textures or audio files

Always ask before making even the simplest models, unless it's coming from ports/

Names

  • The engine is called cubi, all engine names should use the cubi namespace like cubi:air

Layout

  • server/: the game server, world, saves and server-side game logic
  • client/: the browser client: rendering, meshing and lighting workers, UI
  • common/: code shared by both, including world generation, the protocol and the modding API (common/mod_api/)
  • mods/: mods, with JSON data (blocks, items, recipes, worldgen, tags), textures and TypeScript scripts
  • docs/: modding docs and docs/modding_plan.md
  • tests/: Deno tests
  • tools/: dev scripts (mod checking and packing, worldgen preview, benchmarks)
  • ports/: reference source from other projects, not part of the game (see below)
  • build/, server_mods/, dist/, world/: build output and the local world. Don't edit these by hand.

Commands

deno task test                     # every test, takes about 3 minutes
deno test -A tests/door_test.ts    # one test file, prefer this while working
deno task check-mods               # validate and typecheck every mod in mods/
deno task build                    # pack mods and build the client, then keeps rebuilding on changes
deno task server                   # start a server with the mods from the last build
deno fmt                           # format (tabs, 120 columns), applies to JSON too
deno task import KIND IN --output OUT    # convert a java mod's resources, see tools/importer.ts

Tests load mods straight from mods/ through test_game in tests/helpers.ts, so they don't need a build. Run deno task check-mods after changing anything in a mod.

Engine and base game

The engine is what any game built on it needs: rendering, physics, networking, saving, registries, the mod loader, GUI, entities. Game content and rules belong in mods/bworld (data in its JSON folders, behavior in mods/bworld/scripts/). If the base game can't do something as a mod, add what's missing to the modding API rather than special-casing it in the engine, since other mods would hit the same wall. See "The Engine and the Base Game" in docs/modding_plan.md.

When changing the modding API, update the docs that cover it: MODS.md and docs/modding/, which follows the layout of ports/neoforge-docs.

Conventions

  • Classes are PascalCase, everything else is snake_case: functions, variables, fields, files and ids.
  • Before writing something new, search the project for an existing feature that already does it or something close to it, and reuse or extend that. Code duplication is a major problem here and should be avoided.
  • Keep things simple. Don't add abstractions, options or generality the task doesn't need.
  • Private class members use #, not the private keyword.
  • Comments are lowercase and explain why or what something is for, not what the next line does.
  • Don't mention Minecraft by name in comments, and don't paste or reference pieces of its code in them. Comments should explain the code on its own terms.
  • Mod data files start with "format_version": 1, and ids are namespaced by mod (bworld:oak_log). New content should follow the files next to it, so look at a similar block, item or recipe first.
  • Changing a message in common/protocol.ts means bumping PROTOCOL_VERSION.
  • The game is in pre-alpha and backwards compatibility isn't a priority. Only test worlds exist. If supporting old saves or old data takes a lot of code, it's fine to break them instead.
  • Tests should check the behavior they're about, and shouldn't need changing when unrelated parts of the game change. Avoid asserting on specific content (exact block lists, recipe counts, worldgen output, tuned numbers) unless that content is what's being tested.
  • Changing world generation (terrain, ores, features) on purpose makes the worldgen golden tests fail. Record them again with deno test -A tests/worldgen_golden_test.ts -- --update.
  • Commit messages are short and plain, like "Metal ingots and blocks", with no prefixes.

Reference code in ports/

ports/ holds source from other projects to consult, not to edit:

  • ports/neoforge and ports/neoforge-docs: check these whenever adding to the modding API. The API should often resemble NeoForge's.
  • ports/justenoughitems: check when working on the recipe viewer mod (mods/recipe_viewer).
  • ports/sodium: check when looking for rendering optimizations.
  • ports/lithium: check when looking for server optimizations.