pub trait Behavior {
// Required method
fn tick(&mut self, ctx: &mut TickContext<'_>);
// Provided methods
fn name(&self) -> &str { ... }
fn interests(&self) -> Interests { ... }
fn raw_packets(&self, version: GameVersion) -> Cow<'static, [i32]> { ... }
fn start(&mut self, ctx: &mut TickContext<'_>) { ... }
fn running(&self) -> bool { ... }
fn after_tick(&mut self, view: &TickView<'_>) { ... }
fn stop(&mut self, reason: &str) { ... }
}Expand description
A bot behaviour: the code that decides what the player does each tick.
Behaviours never see packets or versions: they read a TickContext and call its
actions. A panic in a behaviour stops that behaviour (its Behavior::stop is called with
"panic") but not the connection: the player keeps standing and answering the server.
Required Methods§
Sourcefn tick(&mut self, ctx: &mut TickContext<'_>)
fn tick(&mut self, ctx: &mut TickContext<'_>)
Called every tick while the player is in the world and the server is answering.
Provided Methods§
Sourcefn interests(&self) -> Interests
fn interests(&self) -> Interests
Optional packet groups this behaviour needs. Read every tick; a change updates the packet filter. Everything not asked for is dropped before it is decoded.
Sourcefn raw_packets(&self, version: GameVersion) -> Cow<'static, [i32]>
fn raw_packets(&self, version: GameVersion) -> Cow<'static, [i32]>
Extra clientbound play packet ids (of version) to copy undecoded into
TickEvents::raw, including packets the core consumes itself (the core’s handling
does not change). Read every tick like Behavior::interests; a change updates the
packet filter. Decoding is the behaviour’s job (ghast::protocol::v1_8::play::clientbound
/ v1_16_5).
Sourcefn start(&mut self, ctx: &mut TickContext<'_>)
fn start(&mut self, ctx: &mut TickContext<'_>)
Called on the first tick the player is in the world, before that tick’s
Behavior::tick (both see the same events).
Sourcefn running(&self) -> bool
fn running(&self) -> bool
Whether the behaviour still wants ticks. Once it returns false the behaviour is done:
it is not ticked again (the player keeps standing and answering the server) and
Behavior::stop still runs when the session ends. Read after every start / tick.
Sourcefn after_tick(&mut self, view: &TickView<'_>)
fn after_tick(&mut self, view: &TickView<'_>)
Called after every tick’s movement step (also while the behaviour is on hold or has finished), with a read-only view of what the server now has: the pose sent this tick, the world, entities and inventory. For observers (a viewer, a recorder); it cannot act. Default: nothing.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<B: Behavior + ?Sized> Behavior for Box<B>
A boxed behaviour is a behaviour (a runner can pick one from its config at run time).
impl<B: Behavior + ?Sized> Behavior for Box<B>
A boxed behaviour is a behaviour (a runner can pick one from its config at run time).