Core concepts
Inventory
After this page you can read the inventory, click slots without desyncing from the server, and handle refused or rejected clicks.
The model
ctx.inventory() returns the session's ghast_inventory::Inventory
(docs). It
holds what the vanilla client holds: the player inventory, the cursor stack and the open
window, fed by the server's window packets as they arrive.
let inv = ctx.inventory;
if let Some = inv.held
let arrows = inv.count;
if let Some = inv.window
There are two numberings. player(k) uses the player inventory index: 0 to 8 hotbar, 9 to 35
main, 36 to 39 armor (feet to head), 40 offhand. slot(i) uses the numbering of the screen
that is open, as vanilla sends it in clicks. In window 0 (the player inventory screen) that is
0 crafting result, 1 to 4 grid, 5 to 8 armor, 9 to 35 main, 36 to 44 hotbar, and 45 offhand
on 1.12 and later. In a chest the container's slots come first and the player's 36 follow;
slot_of_player(k) converts.
Stacks and lazy NBT
A Stack keeps its NBT (26.x: its data component patch) as raw bytes. Receiving a full window
parses none of it. The accessors decode only what they read: item_name(v),
max_stack_size(v), damage_value(v), custom_name(v), enchantments(v). Each takes the
inventory's version, because ids and layouts differ.
Clicking
ctx.click(Click) sends one window click. The click kinds mirror vanilla's modes:
Click | what the player does |
|---|---|
Pickup { slot, right } | left or right click; slot: OUTSIDE drops the cursor |
QuickMove { slot, right } | shift-click |
Swap { slot, hotbar } | number key over a slot |
Drop { slot, all } | Q or ctrl+Q over a slot |
PickupAll { slot } | double click |
Clone, QuickCraft | creative middle click and drags (26.x) |
Before anything is sent, ghast runs the version's own click code on a copy of the inventory
(vanilla's onSlotClick, on 26.x AbstractContainerMenu.doClick) and commits the result. This
is vanilla's client-side prediction, and it matters for a bot for two reasons:
- No desync. On 1.8.9 to 1.16.5 the click packet carries the stack vanilla's code returns, and the server compares it with its own result. After an accepted click the server sends no correction: it assumes the client predicted right. A bot that guesses wrong works with a wrong inventory from then on.
- Anticheat. The packets are byte-identical to the real client's, and the order rules Grim's PacketOrder checks look at hold: at most one click per tick, none in the tick the inventory was opened, none while the player is turning.
The prediction is checked against the real client code: 0 diffs over about 154,000 random clicks per version on 1.8.9 to 1.16.5, 237,292 each on 26.1 and 26.2 and 493,900 on 26.3, every menu included (root README). In the lab, 30 of 30 clicks were accepted on 1.8.9 and 1.16.5 with 0 Grim flags (2026-11-04).
When the outcome depends on data ghast does not model, the click is refused with
ClickError::Unpredictable: nothing is sent, nothing changes.
The confirm protocol
On 1.8.9 to 1.16.5 the server answers every click with a confirm carrying its action number.
ghast keeps one click in flight: the next one gets ClickError::Pending until the confirm
arrives, or until it times out after 40 ticks. A rejected click makes the server resend the
window, and clicks get Resyncing until that arrives. The answer vanilla sends to a rejected
confirm is produced by the inventory, exactly once; you never send it yourself.
The result of each click arrives in ctx.events().inventory.clicks on a later tick:
for c in &ctx.events.inventory.clicks
// ...
match ctx.click
Clicks in window 0 need the player inventory open: call ctx.open_inventory() first (1.8
sends a packet for it; later versions send nothing) and ctx.close_window() when done.
Opening containers
A container opens the way it does for a player: look at the block and right-click it (place
with the sent crosshair on it, as the inventory_probe example does). The server's open
arrives as ctx.events().inventory.opened; wait until ctx.inventory().resyncing() is false
before clicking. The ext helpers wrap all of this as open_container,
deposit, withdraw and close_window.
Special screens have their own calls: select_trade, anvil_rename, click_button,
select_loom_pattern and set_mount_rules.
Per-version differences
- 1.8.9 keeps zero-count stacks, as vanilla 1.8 does, and computes crafting results itself from its 373 recipes.
- 1.12.2 never computes crafting results: the result slot shows what the server last sent,
possibly stale.
result_current()says whether it belongs to the grid as it is now. - 1.16.5 needs
Interests::RECIPESfrom the start of the session. Without the server's recipes and tags, the clicks that read them (furnace shift-clicks, fuel slots, the stonecutter, the smithing table, the beacon) are refused as unpredictable. - 26.x has no confirm. The client sends the slots its prediction changed as hashed stacks,
and the server answers only slots whose hash differs. Silence is acceptance: a click counts as
Acceptedafter a few ticks without a correction (4 by default). A 26.x click is never refused for missing data; it is sent unpredicted and the server's corrections bring the result. Swapwithhotbar: 40(the swap-hands key) works on 1.16.5, not on 1.12.2; 1.8.9 has no offhand.