Skip to main content

Crate ghast_pathfinder

Crate ghast_pathfinder 

Source
Expand description

Physics-exact path planning and following for the ghast Minecraft Java Edition bot library.

  • Pathfinder: A* over feet blocks. Moves: walk (incl. step-ups onto slabs and partial blocks), diagonal, jump up, drop down (configurable maximum fall), gap jumps (up to 3 blocks, also one up or down; each validated in the physics), swimming, ladder / vine climbing, doors and fence gates (opened with a click), and optionally digging (also straight down) and placing (filling holes, bridging gaps, towering up). Costs are ticks measured with ghast-physics (see Costs). Unknown (unloaded) blocks are never treated as air: they are impassable, and a goal beyond them yields a partial path.
  • Controller: turns a path into per-tick keys and aim. It picks the keys by simulating the vanilla-exact physics one tick ahead, and turns in whole mouse counts exactly like the client does, so a simulated run and a live run make the same decisions.
  • simulate: runs a path with the controller in ghast-physics; the validation tests use it to check every move type on random terrain, and Pathfinder::plan_verified uses it to repair a plan before the bot moves.
  • Follower (feature client, default): a ghast_client::Behavior helper that plans, follows, replans on deviations, teleports and blocked moves, all through TickContext.
use ghast_pathfinder::{Config, Goal, Pathfinder, Version};

let mut world = ghast_physics::v1_8::memory_world();
world.load_chunks(-2, -2, 2, 2);
world.fill_raw([-20, 63, -20], [20, 63, 20], 1 << 4); // stone floor
world.fill_raw([3, 64, -5], [3, 64, 5], 1 << 4); // a low wall to jump over
let pf = Pathfinder::new(Config::default());
let path = pf.plan(Version::V1_8, &world, [0, 64, 0], &Goal::Block([8, 64, 0])).unwrap();
assert!(!path.partial);
assert_eq!(path.steps.last().unwrap().pos, [8, 64, 0]);

Structs§

Budget
How much work one Search::step may do.
Command
What the controller wants this tick.
Config
Planner options. Build with Config::default and the with_* methods.
Controller
Follows a Path tick by tick.
ControllerConfig
Options of the Controller. Build with ControllerConfig::default and the with_* methods.
Costs
Measured movement facts of one version (ticks and blocks per tick).
DigCost
Digging through blocks (off by default): cost per block in ticks base + ticks_per_hardness * hardness, blocks harder than max_hardness are never dug.
FollowConfig
Options of the Follower. Build with FollowConfig::default and the with_* methods.
Follower
Plans and follows a path from a behaviour’s tick: call Follower::tick once per tick from Behavior::tick. It sets the aim, the movement keys and (for digs) the left button through the TickContext, so the client’s rules hold: rotation in whole mouse counts, actions before the tick’s single movement packet, digs / places only with the sent crosshair on the block.
Observation
What the follower observes of the player (the client’s Pose, version-free).
Path
A planned path.
Pathfinder
The path planner. Cheap to clone; holds only its configuration.
Place
A block to place before (or during) a step: the new block at pos, clicked on the face of against toward pos (against is a neighbour of pos: the block below it when filling a hole or towering up, the floor block beside it when bridging).
Search
A resumable path search (Pathfinder::search). Owns its state (Send, no borrows), so it can live in a behaviour between ticks.
SimReport
The result of simulate.
Simulation
A resumable simulate: Simulation::step runs a slice of ticks, so a follower can verify a long path across several game ticks. Owns its state (no borrows).
Step
One step of a path: the feet block to reach and how.

Enums§

FollowError
Why following failed.
FollowStatus
What the Follower is doing.
Goal
A path goal. Positions are feet blocks (the block the player’s feet are in).
MoveKind
How a step is reached from the previous one.
NodeKind
How the player is held up in a node.
PlanError
Why planning failed.
Progress
Where the controller is.
SimOutcome
How a simulated run ended.
Version
The protocol version whose blocks and physics a plan uses.

Traits§

BlockSource
Read access to raw block states, as the version encodes them on the wire: 1.8 id << 4 | meta, 1.16.5 and 26.1 the global palette id.

Functions§

simulate
Runs path in world with a Controller: the player starts standing at the first step’s centre, facing the second, and the physics is ghast-physics (bit-exact vanilla) for the path’s version. Digs complete after 5 + 30 × hardness ticks (a bare hand’s order of magnitude) and places after 4 ticks (a stone block appears); the world itself is not changed.