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:
| crate | depends on |
|---|---|
ghast-protocol, ghast-data, ghast-auth | no other ghast crate |
ghast-physics | data |
ghast-inventory, ghast-entity | protocol, data |
ghast-world | protocol, data, physics (optional, default feature physics) |
ghast-client | protocol, auth, data, world, physics, inventory, entity |
ghast-pathfinder | data, physics, client (optional, feature client) |
ghast-ext | client, data, pathfinder (optional) |
ghast-viewer | client, protocol, world, entity, inventory, data |
ghast | client, 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 stateplus 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 (Nonemeans not loaded, never air). Also home ofSharedChunks.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(featureext): sequential async helpers on the tick model (look, dig, place, equip, containers, chat, events,goto). See Async helpers.ghast-pathfinder(featurepathfinder): A* planning with physics-measured costs and a path follower; every move type is checked in the physics. See Pathfinding.ghast-viewer(featureviewer): 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-protocolreads each version'sprotocol.jsonfrom PrismarineJS minecraft-data (pinned 3.119.0, downloaded into the git-ignored.cache/) and writescrates/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 incodegen/protocol/delta/<protocol>.jsonis applied (776 and 777 today).ghast-codegen-datawritescrates/ghast-data/src/generated/;--checkfails 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
| change | where to look |
|---|---|
| a packet's layout or a new protocol | codegen/protocol and its deltas, then ghast-protocol |
| block, item or entity facts | codegen/data, ghast-data |
| how the player moves | ghast-physics; evidence from the oracle |
| clicks and container rules | ghast-inventory |
| login, proxies, accounts | ghast-auth; client.rs in ghast-client for the login flow |
tick order, actions, TickContext | ghast-client/src/engine |
| per-version packet mapping | ghast-client/src/version |
| per-version world and mover glue | ghast-client/src/sim |
| a new 26.x version | the 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.