Skip to main content

Controller

Struct Controller 

Source
pub struct Controller { /* private fields */ }
Expand description

Follows a Path tick by tick.

Pure (no I/O, no clock): it reads an Observation of the player and the world, and answers with an aim target and keys. Where a decision depends on the physics (when to jump off an edge, when to let go of the keys to land on a block, whether a step would leave the floor) it runs ghast-physics a few ticks ahead from the observation, so a simulated run (crate::simulate) and a live run make the same decisions.

Each tick is two calls, because the client turns toward the aim in whole mouse counts and the keys must be chosen for the look the movement step will really use:

  1. Controller::aim: advances along the path and returns the look to aim at;
  2. the caller sets that aim and asks for the look this tick’s movement will use (TickContext::planned_look in ghast-client);
  3. Controller::keys: the keys (and a dig / place job) for that look.

It never gives up silently: Controller::progress turns Progress::Stuck or Progress::OffPath and Controller::current_move names the move, to plan around.

use ghast_pathfinder::{Config, Controller, ControllerConfig, Goal, Pathfinder, Progress, Version};

let mut world = ghast_physics::v1_8::memory_world();
world.load_chunks(-1, -1, 1, 1);
world.fill_raw([-10, 63, -10], [10, 63, 10], 1 << 4);
let path = Pathfinder::new(Config::default())
    .plan(Version::V1_8, &world, [0, 64, 0], &Goal::Block([5, 64, 0]))
    .unwrap();
let mut c = Controller::new(path, ControllerConfig::default());
// Each tick, with `obs` the player's observation:
let (yaw, pitch) = c.aim(&obs, &world);
// ... the client turns toward (yaw, pitch); `look` is what this tick's movement uses.
let look = (yaw, pitch);
let cmd = c.keys(&obs, look, &world);
assert_eq!(c.progress(), Progress::Moving);
assert!(cmd.keys.forward || cmd.keys == ghast_physics::Keys::NONE);

Implementations§

Source§

impl Controller

Source

pub fn new(path: Path, cfg: ControllerConfig) -> Self

A controller at the start of path.

Source

pub fn set_modern_player(&mut self, player: &PlayerState)

26.1: the live client player (ghast_client::TickContext::modern_player), whose attributes (movement speed, step height, jump strength, scale, …), effects, abilities, input timers and build height the one-tick look-ahead and the pre-jump check simulate with. Set it every tick before Controller::aim (the Follower does). Without it the look-ahead uses vanilla defaults rebuilt from the Observation.

Source

pub fn path(&self) -> &Path

The path being followed.

Source

pub fn reached(&self) -> usize

Index (into Path::steps) of the last step reached.

Source

pub fn progress(&self) -> Progress

The current state.

Source

pub fn config(&self) -> &ControllerConfig

The configuration.

Source

pub fn waypoint(&self) -> Option<[f64; 3]>

The point the controller walks to now: the centre of the next step’s feet block at its feet height (None once the last step is reached).

Source

pub fn current_move(&self) -> Option<([i32; 3], [i32; 3])>

The move (from, to feet blocks) the controller is on: after Progress::Stuck / Progress::OffPath the move that failed, for Pathfinder::plan_avoiding.

Source

pub fn aim<S: BlockSource + ?Sized>( &mut self, obs: &Observation, world: &S, ) -> (f32, f32)

Advances along the path from obs and returns the look (yaw, pitch) to aim at this tick. Call once per tick, before Controller::keys.

Source

pub fn keys<S: BlockSource + ?Sized>( &mut self, obs: &Observation, look: (f32, f32), world: &S, ) -> Command

The keys (and dig / place job) for this tick, given the look the movement step will use (look, after the client’s turn toward Controller::aim’s target).

Trait Implementations§

Source§

impl Clone for Controller

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Controller

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V