Skip to main content

Goal

Trait Goal 

pub trait Goal:
    Send
    + Sync
    + 'static {
    // Required methods
    fn flags(&self) -> GoalFlags;
    fn can_use(&mut self, cx: &mut GoalContext<'_>) -> bool;

    // Provided methods
    fn can_continue(&mut self, cx: &mut GoalContext<'_>) -> bool { ... }
    fn start(&mut self, _cx: &mut GoalContext<'_>) { ... }
    fn stop(&mut self, _cx: &mut GoalContext<'_>) { ... }
    fn tick(&mut self, _cx: &mut GoalContext<'_>) { ... }
    fn requires_update_every_tick(&self) -> bool { ... }
    fn is_interruptable(&self) -> bool { ... }
    fn name(&self) -> &'static str { ... }
}
Expand description

A mod’s own mob goal, run by the mob’s goal selector beside vanilla’s: the same priorities and interruption, its state its own (one object per mob, built in crate::EntityPart::register_goals at every Mob construction, so a mob loaded from a chunk gets fresh goals and nothing of them is saved).

The draws a goal makes come from GoalContext::random, the mob’s own random, so its stream keeps vanilla’s shape. A goal that needs memory across saves keeps it in attachments, as vanilla keeps none either.

Required Methods§

fn flags(&self) -> GoalFlags

The flags the goal claims while it runs.

fn can_use(&mut self, cx: &mut GoalContext<'_>) -> bool

Goal.canUse: whether the goal may start now.

Provided Methods§

fn can_continue(&mut self, cx: &mut GoalContext<'_>) -> bool

Goal.canContinueToUse: whether a running goal keeps running. Defaults to can_use.

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

Goal.start: the goal began running.

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

Goal.stop: the goal stopped, replaced or done.

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

Goal.tick: the goal’s every-other-tick (or, with requires_update_every_tick, every tick) step while it runs.

fn requires_update_every_tick(&self) -> bool

Goal.requiresUpdateEveryTick: tick every tick, not at vanilla’s reduced cadence.

fn is_interruptable(&self) -> bool

Goal.isInterruptable: false keeps a lower-priority goal from replacing this one (the flags it holds stay locked until it ends).

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

The goal’s name for debugging (Goal.toString).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§