Files

6.5 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 client: rendering, meshing and lighting workers, UI. client/native/ runs it in the desktop app
  • desktop/: the desktop app: its window, sound, singleplayer and client updates (see "Desktop first")
  • 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 task desktop                  # run the desktop app with what the last build made
deno task compile [linux] [windows]    # build the desktop app's executables into dist/
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.

Desktop first

The desktop app is the main target and the browser a secondary one, so build and try new features in the desktop app first. The app (desktop/) is an SDL3 window that the client draws into with Deno's WebGPU, running in a Deno worker (client/native/), with sound through OpenAL Soft and a singleplayer server of its own.

  • The client keeps using web APIs: WebGPU, Web Audio, fetch, WebSocket. Where Deno doesn't have one, polyfill the part the game uses, like client/native/web_audio.ts does over OpenAL, instead of writing engine code only the desktop app can run.
  • What has to differ between the two goes through Platform (client/platform.ts), which client/browser_platform.ts and client/native/main.ts implement, rather than checks for the DOM in shared code.
  • Keep the browser working, but a browser limitation doesn't block a feature: it can be missing or simpler there.
  • The client worker runs servers' mods, so it only gets the network and reading its own files, and gives up FFI once the window's surface exists. Don't widen its permissions.
  • The Windows build ships SDL3 and OpenAL Soft from desktop/windows/: unmodified files from their tagged releases, with their licenses and where they came from in credits.txt there, which the app shows in its credits. Update it along with the DLLs.

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/horizon: cleanroom implementation of minecraft, very useful for a lot of various things
  • 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.