ghast-ext
Sequential, mineflayer-style async helpers for ghast bots. ghast's bot API is a per-tick
state machine (Behavior::tick): exact and cheap, but every multi-step job becomes an
explicit state enum. ghast-ext lets you write the same job as straight-line async code
without giving up the tick model.
Versions: one cargo feature each, v1_8, v1_12_2, v1_16_5, v26_1, v26_2, v26_3 (default: all,
plus pathfinder), forwarded to ghast-client, ghast-data and the path finder. goto works on
every version (1.8.9, 1.12.2, 1.16.5, 26.1, 26.2, 26.3). Item and block names and ids follow the
connection's version, 26.x included.
use ;
use ;
# async
How it works
Ext is a Behavior with a tiny single-threaded executor inside. Every tick it polls the
tasks that are ready; a task reaches the game only through Bot::with, which hands a closure
to the executor to run with that tick's TickContext and resumes the task in the same tick.
So every action is written inside Behavior::tick, before the tick's single movement packet,
in call order; dig / place are refused unless the sent crosshair is on the block (the
helpers aim first and act on a later tick); clicks wait while turning or while another click
is in flight; rotation is whole mouse counts. Nothing runs between ticks, the silent-server
guard holds everything, and there is no unsafe.
Helpers fail with Error when the world changes under them (teleport / setback, death), and
dropping a helper's future releases the keys and buttons it held. One task should own the
look and the movement keys at a time.
API
- Executor:
Ext::new(main)withname,interests,when_done,auto_respawn,interrupt_on_teleport,bot,result;Bot::with,act,wait_ticks,next_tick,sleep,timeout,wait_until,spawn(JoinHandle: await,abort,is_finished),require; snapshot readstick,version,pose,sent,eyes,health,is_dead,game_mode,held_slot,open_window,entity_id,dimension. - Looking:
look,look_at,look_at_block,yaw_pitch. - Hands:
dig,dig_with(DigOptions),place,activate_block,consume,activate_item,deactivate_item,swing,attack. - Items:
count,find_item,held_item,select_slot,equip,equip_for_block,swap_to_hotbar,drop_slot,toss,click,close_window,open_container,container_items,deposit,withdraw;ItemMatch(name, id or predicate),item_id,item_name. - World:
block_at,find_blocks,find_block(BlockMatch: name, names or predicate;Blocknames raw states),find_entities,nearest_entity,entity,player. - Chat and events:
chat,command,wait_for_chat,wait_for,events(Eventstream),respawn,disconnect. - Moving:
walk_straight_to,follow(straight line),set_controls;goto/goto_with,follow_path/follow_path_with(featurepathfinder, on by default: ghast-pathfinder's planner and follower, re-exported asghast_ext::pathfinder).
Tests
tests/helpers.rs runs every helper group against an in-process 1.8 fake server
(tests/support) with a real login, real 50 ms ticks and real packets: look (server sees
the final look), look-at-block (face, out of reach, not loaded), dig (start / finish packets,
the swing and the movement packet after the start in the same tick, refusals), place and
equip from the hotbar (refusals), equip from the main inventory (number-key swap click),
toss, chest withdraw / deposit (shift clicks), chat / commands / events / teleports,
teleport interrupting a walk (keys released), straight walking, block and entity search,
the executor (ticks, same-tick with, timeouts, spawn / abort / panics, act order) and
goto around a wall.
Licensed under MIT OR Apache-2.0.