ghast-physics
Vanilla-exact player movement for the ghast Minecraft Java Edition client library. A pure,
deterministic function: (player state, tick input, world view) -> new state + the movement packets of the tick. No IO, no async, no clock, no mutable global state (the only static is
vanilla's constant 65536-entry sine table, built once).
| module | version | verification |
|---|---|---|
v1_8 |
1.8.9 (protocol 47) | bit-exact against the vanilla oracle (see below) |
v1_12 |
1.12.2 (protocol 340; the rules hold for every 1.12 release) | bit-exact against the vanilla oracle (see below) |
v1_16_5 |
1.16.5 (protocol 754) | bit-exact against the vanilla oracle (see below) |
Use
use ;
Per client tick the caller (ghast-client) does what MinecraftClient.tick does:
- apply inbound packets that arrived since the last tick, in order:
PlayerState::apply_velocity_packet(x, y, z)(raw 1/8000 units),apply_teleport(pos, yaw, pitch, relative_flags)(returns thePositionLookconfirmation the client sends immediately; it does not touchsent, like vanilla),apply_abilities(..), and plain field writes for the rest (movement_speed_basefrom entity properties,food_levelfrom update health,effectsfor jump boost / blindness);TickInput::using_itemis the client's item-use state (eating, blocking, bow) for this tick — the use / release packets themselves are sent by the client; - write this tick's actions (dig / place / click) — they are judged with
state.sent, the pose the server has; v1_8::tick(&mut state, &input, &world, &mut out)and sendoutin order.
PlayerState is Copy: clone it to plan ahead (look-ahead pathing, "where will I land") with the
same code path.
The world: BlockView
Contract: block is only called with |x|, |z| < 30_000_000 and 0 <= y < 256; it must return
states as vanilla decodes chunk data (BlockState::from_raw_vanilla: unknown ids and unregistered
metas are air) and air for columns that are not loaded (vanilla's client uses an empty chunk:
no collision; the only other effect of an unloaded column is the gravity rule below).
MemoryWorld (v1_8::memory_world()) is a simple implementation for tests, benches and tools.
Rotation helpers (rotation)
mouse_multiplier(sensitivity), mouse_step_degrees, turn(yaw, pitch, yaw_counts, pitch_counts, multiplier) reproduce the 1.8 renderer + entity angle update in whole mouse counts
(the "GCD" anti-cheats check), wrap_degrees. How many counts to move per tick (aim speed,
budgets) is client policy and stays out of this crate.
Design decisions
- Version rules are modules, selected at compile time.
v1_8has its ownPlayerState, block rules andtick.Ruleset(implemented byv1_8::V1_8) lets the client be generic over versions with static dispatch; nothing on the hot path is dynamic. 1.16.5 will be a sibling module with its own state type (sneaking/swimming poses differ) behind the same trait. - Exactness first, structure our own. Each step keeps vanilla's precision (
f32vsf64, widening points,int + floatproducing a float, truncation vs floor, JavaMath.min/maxzero-sign rules,Vec3d's-0.0 -> 0.0, NaN behaviour of negated comparisons). The code is organised in our own way (one context struct, shared sweep helpers, geometric stairs and door rules), not a transliteration. - Collision shapes: static shapes come from
ghast-data; this crate adds what a table cannot express: neighbour-dependent fences, panes, walls, stairs (outer/inner corners) and doors (each half reads the other half's metadata). - History-dependent shapes are an option. 1.8.9 anvils, chests and trapped chests collide
with whatever bounds the last shape update of any block of that type left behind.
v1_8::Options { history_shapes }selectsHistoryShapes::Settled(default, project policy: anvil by facing, chest extended towards the first same-kind chest north/south/west/east — what Grim models) orConstructor(anvil full cube, single-chest inset — what a fresh client and the oracle's movement harness have).tickuses the default;tick_withtakes options. The golden and fuzz replays run withConstructor; the box-dump tests checkSettledagainst every"settled"line andConstructoragainst the rest. - Block data from
ghast-data: static shapes are placed withCollision::world_boxes, which reproduces vanilla'sfloatworld-coordinate boxes (cactus, cake, fence gates; soul sand and snow only on y) and the sorting box constructor; per-block flags (full cube, full block, render as normal block, material identity and blocks-movement / solid / fluid / opaque) come fromBlock::vanilla()/Block::material(). A unit test checks the derived predicates (incl. the fence/wall connection rule) against the oracle dump. - Collision queries fill a small inline box list (no allocation unless a query finds more than 24 boxes); emptiness checks (sneak edge guard, liquid jump-out) stop at the first box. Every query updates the world-border flag exactly as vanilla's does.
- Packets come out as a fixed-capacity
Packetslist in send order.
Vanilla behaviours worth knowing (all verified)
- Tick order: water contact (flow push 0.014) → lava halves fall distance → sprint timer → input (sneak ×0.3) → push out of blocks (4 probes at minY + 0.5) → sprint (double tap within 7 ticks, sprint key, stop on forward < 0.8 / horizontal collision / food ≤ 6) → creative flight double tap → fly up/down impulse → velocity cut-off (|v| < 0.005) → jump (0.42, +0.1 per jump boost level, sprint +0.2 along yaw; water/lava +0.04) → input ×0.98 → travel → air acceleration for the next tick (0.02 / 0.026 sprinting: sprint changes reach the air one tick late) → landing ends flight → x/z clamp ±29,999,999 → packets.
- Travel: ground acceleration
attr * 0.16277136 / f³withf = slipperiness * 0.91of the block at(floor x, floor minY − 1, floor z); ladders/vines clamp to ±0.15, stop descent while sneaking, climb 0.2 on horizontal collision; water drag 0.8, lava 0.5, jump out at a ledge 0.3. - Gravity −0.08 ×0.98; when the column at
((int) x, (int) z)(truncation) is not loaded the player instead getsvelY = −0.1(0 at y ≤ 0). - Move: cobweb (×0.25 / ×0.05, velocity zeroed), sneak edge guard in 0.05 steps, clip Y→X→Z, step-up 0.6 (two candidate paths), slime bounce / slime walking ×(0.4 + |vy|·0.2), soul sand ×0.4 per contained block, fall distance, landing re-checks water.
- Outside the world border (default ±29,999,984) blocks collide as stone while the player is inside it.
- Movement packet: position when moved² > 9e-4 or every 20 ticks, rotation when the float difference is non-zero; sprint/sneak entity actions before it; flight toggles send abilities.
1.12.2 (v1_12): what changed since 1.8.9
v1_12 has the structure of v1_8 (same calling convention, PlayerState is Copy) and is the
first member of the 1.9 – 1.12 family. Everything below is verified against the vanilla 1.12.2
oracle (tests/golden/1.12.2/, oracle/README.md "1.12.2"):
- Ticking: the client only ticks a player its world has added to a chunk: a player spawned
above a column that is not loaded neither moves nor sends anything until the column arrives
(
PlayerState::added_to_chunk); once added it keeps ticking over unloaded columns, falling at −0.1 there (the column test floors x / z; 1.8 truncated). - Constants: velocity cut-off 0.003 (1.8: 0.005); input acceleration converts the yaw with
one
floatmultiply (yaw * 0.017453292F) and has a (zero) vertical component, which turns a-0.0vertical velocity into+0.0. - Sneaking: the edge guard probes one step height (0.6) down instead of one block, so a sneaking player walks down half-block drops; after the move the box becomes 0.6 × 1.65 while sneaking (1.8 when not) if the new box is free, rebuilt from its minimum corner; the step effects (slime walking) are skipped when the player is sneaking on the ground after the move.
- Flying: sneaking no longer slows horizontal flight (the input is divided by 0.3 again); flight resets the fall distance.
- Effects / blocks: levitation replaces gravity (
vy += (0.05 · (amp + 1) − vy) · 0.2); beds bounce (vy = −vy · 0.66Funless sneaking); an open trapdoor above a ladder with the same facing is climbable. - Collision query: one block wider on x / z (corner columns and the top layer of edge columns skipped); no validity filter on columns, so the size check counts columns beyond ±30,000,000 as colliding. Axes with a zero offset are not clipped or moved.
- Fluids: every material query iterates
floor(min) .. ceil(max); falling water pulls down next to a solid face (by the 1.12 face shape, stairs and the attach exclusion list excepted). - Shapes (
blocks.rs): no history-dependent shapes; fences are a post plus one box per arm and connect by the neighbour's face shape (same material or a gate for fence posts), panes a post plus arms, walls one box; doors read the other half's decoded properties when it is the same door (a half whose metadata does not carry a property has the palette's hidden default: the last value — facing east, closed, right hinge); chests reach towards a chest of the same kind; chorus plants grow arms towards chorus blocks (and end stone below). - Packets: a bare on-ground packet only when
on_groundchanged (no idle packets), the position refresh on the 20th tick; teleports clamp x / z to ±3e7 and the pitch to ±90 and are answered withteleport_confirm(sent by the client crate) thenposition_look. - Auto-jump is not modelled (bots never auto-jump; the oracle runs with it off).
Verification
cargo test runs:
tests/golden.rs: every committed vector —tests/golden/1.8.9/scenarios.jsonl.gz(80 cases, 3,245 ticks, incl. 4 item-use cases) andfuzz_seed1.jsonl.gz(100 × 60 = 6,000 ticks). Interaction packets in the records (block_place/block_digof item use) are the client crate's and are not compared. Every recorded state field (position, box, velocity, all flags, timers, speeds, input,sentbookkeeping, the derivedtouching_lava/climbing) and every packet is compared by its bits; the tick-0 record must round-trip too. A mismatch prints case, first differing tick, field path, expected and actual (hex + decimal). Result: 0 diffs.src/v1_8/tests.rs: all 4,442 lines ofcollision_boxes.jsonl.gz(every id × meta alone and in the dumped neighbour configurations, the 184 "settled" lines withSettled, the rest withConstructor) produce exactly the oracle's boxes; all 9,648collision_boxes_far.jsonl.gzlines (absolute boxes at three far positions, incl. just past 2^24) match too — this caught the float-built cake box whose rounded min exceeds its max there (vanilla's box constructor sorts); the block-flag table equals the dump's block lines.math: the sine table's bit hash equals the one a JDK builds.
Large fuzz (feature oracle-cache, reads the git-ignored oracle/cache/1.8.9/fuzz/*.jsonl.gz or
$GHAST_FUZZ):
for; do # add --use-item true for item-use spans
done
for; do # wider palette: doors, chests, anvils, liquids, events, item use
done
Extras fuzz (server speed modifiers of every operation incl. negative ones, depth strider,
spectator no-clip): oracle/run.sh fuzz --extras true --seed S --count 2000 --ticks 100 --out "$PWD/oracle/cache/1.8.9/fuzz-extras/extras_sS.jsonl.gz"; seeds 41-45 = 1,000,000 ticks, 0 diffs.
Edge fuzz (partial-height blocks next to each other and to full blocks, landing step-ups):
oracle/run.sh fuzz --edges true --seed S --count 2000 --ticks 100 --out "$PWD/oracle/cache/1.8.9/fuzz-edges/edges_sS.jsonl.gz"; seeds 31-35 = 1,000,000 ticks, 0 diffs
(about 320 landing step-ups per 200k ticks). The committed fuzz_edges_seed1.jsonl.gz and the
landing_step_* scenarios cover the case a live Grim test raised.
Last run (2026-11-03): 24,000 cases, 2,160,000 ticks, 0 diffs (oracle fuzz 1,000,000 ticks,
oracle fuzz with --use-item true 200,000 ticks (seed 21), extra fuzz 960,000 ticks; per 160k extra ticks about 14k in water with flow, 4.5k in lava, 7k in
cobweb, 21k flying, 1.8k outside the border, 1,100 teleports, 1,300 abilities and 2,400 velocity
events; seeds 4-6 add item use and origins at ±2^24).
1.16.5: MC=1.16.5 oracle/run.sh fuzz --seed S --count 2000 --ticks 100 --out "$PWD/oracle/cache/1.16.5/fuzz/physics_sS.jsonl.gz"; seeds 11-15 = 1,000,000 ticks, 0 diffs (plus the
committed tests/golden/1.16.5/ scenarios and fuzz_seed1, replayed by tests/golden_1_16_5.rs).
1.12.2: tests/golden_1_12_2.rs replays the committed tests/golden/1.12.2/ scenarios (122 cases),
fuzz_seed1 and fuzz_edges_seed1; src/v1_12/tests.rs checks every line of the 1.12.2 collision
dumps (6,083 box lines incl. neighbour configurations, 12,192 far lines) and the stairs face shapes.
Large fuzz: the same commands with MC=1.12.2 and oracle/cache/1.12.2/ (seeds 11-15, 21 with
--use-item true, extra 1-6 replayed from fuzz-in/, edges 31-35, extras 41-45) = 4,160,000 ticks,
0 diffs.
Total randomized oracle fuzz: 9,320,000 ticks, 0 diffs — 1.8.9 4,160,000 (the 2,160,000 above, 1,000,000 extras, 1,000,000 edges), 1.12.2 4,160,000 and 1.16.5 1,000,000.
Performance
cargo bench -p ghast-physics (x86-64 WSL2, release + fat LTO), per tick, 20-tick sequences:
| case | MemoryWorld (hash per column) |
dense array world |
|---|---|---|
| walk on flat stone | 1.2–1.5 µs | 0.43–0.67 µs |
| busy: sneak on a ledge edge into fences / panes / wall / stairs / slabs under a ceiling, jumping | 1.4–1.7 µs | ~0.54 µs |
(Ranges over several runs on a machine shared with other builds.)
With the real ghast-world worlds (palette sections, hashed columns; measured 2026-11-04 with a
small standalone harness that builds both worlds through their chunk-data API):
| case | 1.8.9 | 1.16.5 before | 1.16.5 after |
|---|---|---|---|
| walk on flat stone | ~0.55-0.58 µs | 6.2 µs | ~2.8 µs |
| busy collision case | ~0.65-0.69 µs | 8.3 µs | ~4.8 µs |
1.16.5 is dearer by design: vanilla's collision scan covers a one-block ring around every query box (fences and walls reach into neighbouring cells), and a tick runs several queries (pose checks, push-out probes, the sweep). What made it cheaper without changing a single result:
- a per-tick 8x8x8 block memo around the player and a 3x3 chunk-loaded memo (
TickCache, both versions); - a per-state collision summary byte (empty / full cube / exceeds cube / moving piston) that rejects most cells with one table read;
- the shapes of a sweep are collected once and reused for all three axes, as vanilla's reusable stream does;
- nested pose boxes (0.6 < 1.5 < 1.8 high, same feet) answer each other, so the pose checks usually cost one query, and the four push-out probes share per-column answers;
- the shape/box overlap test runs on a stack buffer and skips vanilla's redundant separation pre-check.
Even the 1.16.5 busy case at ~5 µs per tick is 0.01 % of a core per bot at 20 tps.
Not covered yet (open)
- Movement speed modifiers beyond the sprint modifier (speed / slowness potions arrive as
attribute modifiers; with several multiply-total modifiers vanilla's hash-set iteration order
matters for the last bit).
movement_speed_basecovers the base value only. - Depth strider, riding, sleeping, spectator, portals / nausea, entity collisions (boats, minecarts) and entity pushing, a moving world border, server-side corrections.
- Falling below y = −64 removes the player (vanilla stops ticking it): modelled as
PlayerState::removed; a real server kills the player first.