pub struct Simulation { /* private fields */ }Expand description
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).
use ghast_pathfinder::{Config, ControllerConfig, Goal, Pathfinder, SimOutcome, Simulation, 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([8, 64, 3]))
.unwrap();
let mut sim = Simulation::new(&path, &ControllerConfig::default());
let outcome = loop {
if let Some(r) = sim.step(&world, 20, None) {
break r.outcome;
}
};
assert_eq!(outcome, SimOutcome::Arrived);Implementations§
Source§impl Simulation
impl Simulation
Sourcepub fn new(path: &Path, cfg: &ControllerConfig) -> Simulation
pub fn new(path: &Path, cfg: &ControllerConfig) -> Simulation
A simulation of path from its first step (standing at the centre, facing the
second), not started yet.
Sourcepub fn with_modern_player(
path: &Path,
cfg: &ControllerConfig,
player: &PlayerState,
) -> Simulation
pub fn with_modern_player( path: &Path, cfg: &ControllerConfig, player: &PlayerState, ) -> Simulation
26.1: like Simulation::new, with the live client player’s attributes (movement
speed, step height, jump strength, scale, …), effects, abilities and build height
(ghast_client::TickContext::modern_player) instead of vanilla defaults. The Follower
verifies its plans this way. On other versions the player is ignored.
Sourcepub fn step<S: BlockSource + ?Sized>(
&mut self,
world: &S,
ticks: u32,
time: Option<Duration>,
) -> Option<&SimReport>
pub fn step<S: BlockSource + ?Sized>( &mut self, world: &S, ticks: u32, time: Option<Duration>, ) -> Option<&SimReport>
Runs at most ticks simulated ticks (and stops after time, checked every 16
ticks); the report once the run has ended (None: call again).
Sourcepub fn report(&self) -> &SimReport
pub fn report(&self) -> &SimReport
The report so far (final once Simulation::step returned it).
Sourcepub fn into_report(self) -> SimReport
pub fn into_report(self) -> SimReport
The report.