ghast v0.5.6

Under the hood

Architecture

This page maps the ghast workspace: what each crate does, how the crates depend on each other, which ones you can use without the rest, and where to look when you want to change something.

The layers

ghast is one workspace of twelve crates with one version number, released together. Each crate is published on its own. Dependencies point one way, from the facade down to the protocol and data crates, which know nothing about the layers above them.

facade      ghast                       (re-exports, cargo features)
               |
optional    ghast-ext   ghast-pathfinder   ghast-viewer
               |
client      ghast-client                (connection, tick loop, Behavior API)
               |
state       ghast-world   ghast-inventory   ghast-entity   ghast-auth
               |
movement    ghast-physics
               |
base        ghast-protocol   ghast-data

A crate uses only crates in lower layers; the one sideways edge is ghast-ext, which can use ghast-pathfinder. The exact graph from the manifests:

cratedepends on
ghast-protocol, ghast-data, ghast-authno other ghast crate
ghast-physicsdata
ghast-inventory, ghast-entityprotocol, data
ghast-worldprotocol, data, physics (optional, default feature physics)
ghast-clientprotocol, auth, data, world, physics, inventory, entity
ghast-pathfinderdata, physics, client (optional, feature client)
ghast-extclient, data, pathfinder (optional)
ghast-viewerclient, protocol, world, entity, inventory, data
ghastclient, protocol, auth, data; ext, pathfinder, viewer behind features

What each crate does

Bottom layer.

  • ghast-protocol: generated packet types per version, framing, compression, encryption, VarInt, NBT and chat components. No game logic.
  • ghast-data: blocks, block states, collision shapes, items, entities and other game tables, generated from minecraft-data.
  • ghast-auth: offline identities, SOCKS5, login encryption, signed-chat keys and Microsoft accounts (see Accounts and proxies).

Game state.

  • ghast-physics: player movement as a pure, deterministic function: (state, input, world view) -> new state plus the tick's movement packets. No I/O, no async, no clock. The oracle tests, trace replays and the pathfinder's look-ahead all call the same code.
  • ghast-world: chunk storage, block lookup, and loaded versus unloaded columns kept apart (None means not loaded, never air). Also home of SharedChunks.
  • ghast-inventory: windows, vanilla's client-side click prediction, the window confirm protocol and lazily parsed item stacks. Pure and sync: packets in, packets out.
  • ghast-entity: opt-in entity tracking, server positions and metadata.

The client. ghast-client holds the connection, the fixed 50 ms tick loop and the Behavior / TickContext API. Its engine (state, behaviour, tick) does no I/O and can be driven by tests directly. At the bottom, packet types are per version; on top, a version-agnostic layer of inbound events and outbound actions is all a behaviour sees. Client::run matches the GameVersion once per session and runs a monomorphised session for that version.

Optional crates, enabled through the facade's features:

  • ghast-ext (feature ext): sequential async helpers on the tick model (look, dig, place, equip, containers, chat, events, goto). See Async helpers.
  • ghast-pathfinder (feature pathfinder): A* planning with physics-measured costs and a path follower; every move type is checked in the physics. See Pathfinding.
  • ghast-viewer (feature viewer): a live 3D view of the bot's world in the browser, with recordings and replays. See Viewer.

The facade. ghast re-exports the client API at the top level and the lower layers as ghast::protocol, ghast::auth and ghast::data, and forwards the version features.

Using a crate on its own

Because dependencies point down, the lower crates stand alone. ghast-protocol is the clearest case: its login_26_1 example runs handshake, status, login, configuration and play against a live server using only that crate. ghast-auth opens proxied connections and runs the Microsoft sign-in without any game code. ghast-physics, ghast-world, ghast-inventory and ghast-entity are sync and I/O-free, so you can feed them packets or states from your own client, a proxy or a test. ghast-pathfinder plans paths without ghast-client when its client feature is off.

Code generation

Packet and game-data tables are not written by hand. The codegen/ directory holds two unpublished generators:

  • ghast-codegen-protocol reads each version's protocol.json from PrismarineJS minecraft-data (pinned 3.119.0, downloaded into the git-ignored .cache/) and writes crates/ghast-protocol/src/generated/. A definition that is identical across versions is emitted once and shared. Where a version needs changes on top of minecraft-data, a reviewed delta in codegen/protocol/delta/<protocol>.json is applied (776 and 777 today).
  • ghast-codegen-data writes crates/ghast-data/src/generated/; --check fails if the committed files are stale.

The output is committed, so a normal build needs no network, Java or Node. Regenerate with cargo run -p ghast-codegen-protocol and cargo run -p ghast-codegen-data, then commit the result.

Where to make a change

changewhere to look
a packet's layout or a new protocolcodegen/protocol and its deltas, then ghast-protocol
block, item or entity factscodegen/data, ghast-data
how the player movesghast-physics; evidence from the oracle
clicks and container rulesghast-inventory
login, proxies, accountsghast-auth; client.rs in ghast-client for the login flow
tick order, actions, TickContextghast-client/src/engine
per-version packet mappingghast-client/src/version
per-version world and mover glueghast-client/src/sim
a new 26.x versionthe row modules described in CONTRIBUTING.md

Other top-level directories: oracle/ runs the real vanilla client (see Accuracy), tests/golden/ holds its committed output, and lab/ has local test servers, measurement and cross-build scripts.

A change to physics, collision, raytrace or click behaviour should come with oracle evidence: new or regenerated vectors, or a fuzz run with seeds and tick counts in the pull request. No Mojang code or files may enter the repository, and traces must hold no private data.