Skip to main content

Behavior

Trait Behavior 

pub trait Behavior:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn check_extra_start_conditions(&mut self, _cx: &mut BehaviorCx<'_>) -> bool { ... }
    fn start(&mut self, _cx: &mut BehaviorCx<'_>) { ... }
    fn can_still_use(&mut self, _cx: &mut BehaviorCx<'_>) -> bool { ... }
    fn tick(&mut self, _cx: &mut BehaviorCx<'_>) { ... }
    fn stop(&mut self, _cx: &mut BehaviorCx<'_>) { ... }
    fn name(&self) -> &'static str { ... }
}
Expand description

A mod’s own brain behavior, run by the species’ brain beside vanilla’s: started by Brain.tick’s start pass when its activity is active and its entry condition holds, ticking until its duration runs out or can_still_use fails, stopped with vanilla’s own stopAll. One object per mob, built in crate::EntityPart::register_behaviors wherever the brain is built, so nothing of it is saved and a rebuilt brain starts fresh.

Provided Methods§

fn check_extra_start_conditions(&mut self, _cx: &mut BehaviorCx<'_>) -> bool

Behavior.checkExtraStartConditions: asked after the entry condition holds, before the duration is drawn.

fn start(&mut self, _cx: &mut BehaviorCx<'_>)

Behavior.start: the behavior began running.

fn can_still_use(&mut self, _cx: &mut BehaviorCx<'_>) -> bool

Behavior.canStillUse: whether a running behavior keeps running. Defaults to false, as vanilla’s does — a behavior that does not override it lives out the brain tick that started it.

fn tick(&mut self, _cx: &mut BehaviorCx<'_>)

Behavior.tick: every brain tick while the behavior runs.

fn stop(&mut self, _cx: &mut BehaviorCx<'_>)

Behavior.stop: the behavior stopped — its end, can_still_use failing, or the brain’s own stopAll.

fn name(&self) -> &'static str

The behavior’s name for debugging (Behavior.debugString).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§