Skip to main content

GoalSpec

Enum GoalSpec 

#[non_exhaustive]
pub enum GoalSpec {
Show 20 variants Float, ClimbOnTopOfPowderSnow, Panic { speed: f64, water_range: Option<i32>, }, Stroll { speed: f64, interval: i32, water_avoiding: Option<f32>, swim: bool, flying: bool, }, LookAtPlayer { range: f32, probability: f32, only_horizontal: bool, mobs: bool, only: Option<String>, }, RandomLookAround, MeleeAttack { speed: f64, follow_unseen: bool, }, LeapAtTarget { yd: f32, }, AvoidEntity { what: MobFilter, max_dist: f32, walk: f64, sprint: f64, }, Tempt { speed: f64, items: Vec<String>, can_scare: bool, }, Breed { speed: f64, }, FollowParent { speed: f64, }, FollowMob { speed: f64, stop: f32, area: f32, }, RestrictSun, FleeSun { speed: f64, }, EatBlock, BreathAir, TryFindWater, NearestTarget { prey: MobFilter, must_see: bool, must_reach: bool, interval: i32, }, HurtByTarget { alert: bool, },
}
Expand description

A vanilla AI goal, as a mob’s add_goal and add_target_goal give one: only the kinds Horizon’s own species code runs, with the vanilla constructor’s parameters (MeleeAttackGoal(speed, followUnseen)). Goals with behavior of their own (a MoveToBlockGoal subclass’s block test) stay out: they take code, not parameters.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Float

FloatGoal: swim up in water or lava. Vanilla parameters: none.

§

ClimbOnTopOfPowderSnow

ClimbOnTopOfPowderSnowGoal: jump onto powder snow. Parameters: none.

§

Panic

PanicGoal(speed), or TurtlePanicGoal(speed) with water_range set: always head for water this far away, not only when on fire.

Fields

§speed: f64

Movement speed multiplier while the goal runs; 1.0 is the mob’s normal speed.

§water_range: Option<i32>

Search distance for water in blocks, as TurtlePanicGoal’s.

§

Stroll

RandomStrollGoal(speed, interval); water_avoiding set to its probability makes WaterAvoidingRandomStrollGoal, swim RandomSwimmingGoal, flying WaterAvoidingRandomFlyingGoal.

Fields

§speed: f64

Movement speed multiplier while the goal runs; 1.0 is the mob’s normal speed.

§interval: i32

Ticks between tries; the goal starts with chance 1 in interval each tick.

§water_avoiding: Option<f32>

Probability, 0 to 1, of preferring a spot away from water.

§swim: bool

Swim around in water instead of walking.

§flying: bool

Pick flying destinations.

§

LookAtPlayer

LookAtPlayerGoal(range, probability, onlyHorizontal): the nearest player, the nearest mob with mobs, or only mobs of only’s species.

Fields

§range: f32

Distance in blocks the goal looks for something to watch.

§probability: f32

Chance, 0 to 1, each tick that the goal starts.

§only_horizontal: bool

Turn the head only sideways, never up or down.

§mobs: bool

Also watch the nearest mob, not only the nearest player.

§only: Option<String>

A mob type id (minecraft:cow) that restricts the mobs watched to that species.

§

RandomLookAround

RandomLookAroundGoal. Vanilla parameters: none.

§

MeleeAttack

MeleeAttackGoal(speed, followUnseen).

Fields

§speed: f64

Movement speed multiplier while the goal runs; 1.0 is the mob’s normal speed.

§follow_unseen: bool

Keep chasing a target the mob can no longer see.

§

LeapAtTarget

LeapAtTargetGoal(leapMotion).

Fields

§yd: f32

The upward speed of the leap, in blocks per tick.

§

AvoidEntity

AvoidEntityGoal(what, maxDist, walk, sprint): sprint away from what once it is closer than max_dist.

Fields

§what: MobFilter

Which entities the mob avoids.

§max_dist: f32

Distance in blocks within which the mob flees.

§walk: f64

Speed multiplier while fleeing at a distance.

§sprint: f64

Speed multiplier while fleeing close by.

§

Tempt

TemptGoal(speed, items, canScare): items are item ids (minecraft:wheat; a bare id reads as minecraft:’s).

Fields

§speed: f64

Movement speed multiplier while the goal runs; 1.0 is the mob’s normal speed.

§items: Vec<String>

Item ids that tempt the mob.

§can_scare: bool

Whether a moving player holding the item scares the mob off.

§

Breed

BreedGoal(speed). An animal keeps it; other mobs refuse it.

Fields

§speed: f64

Movement speed multiplier while the goal runs; 1.0 is the mob’s normal speed.

§

FollowParent

FollowParentGoal(speed). An animal keeps it; other mobs refuse it.

Fields

§speed: f64

Movement speed multiplier while the goal runs; 1.0 is the mob’s normal speed.

§

FollowMob

FollowMobGoal(speed, stopDistance, areaSize).

Fields

§speed: f64

Movement speed multiplier while the goal runs; 1.0 is the mob’s normal speed.

§stop: f32

Distance in blocks at which the mob stops following.

§area: f32

Radius in blocks searched for a mob to follow.

§

RestrictSun

RestrictSunGoal. Vanilla parameters: none.

§

FleeSun

FleeSunGoal(speed).

Fields

§speed: f64

Movement speed multiplier while the goal runs; 1.0 is the mob’s normal speed.

§

EatBlock

EatBlockGoal. Vanilla parameters: none.

§

BreathAir

BreathAirGoal. Vanilla parameters: none.

§

TryFindWater

TryFindWaterGoal. Vanilla parameters: none.

§

NearestTarget

NearestAttackableTargetGoal (the target selector): hunt prey, checking every interval ticks, must_see (mustSee) and must_reach (mustReach).

Fields

§prey: MobFilter

Which entities the mob hunts.

§must_see: bool

Only pick a target the mob can see.

§must_reach: bool

Only pick a target the mob can path to.

§interval: i32

Ticks between tries; the goal starts with chance 1 in interval each tick.

§

HurtByTarget

HurtByTargetGoal, alert as its setAlert().

Fields

§alert: bool

Also alert nearby mobs of the same kind, as setAlert().

Implementations§

§

impl GoalSpec

pub fn id(&self) -> &'static str

The goal’s kind id: the same snake_case spelling goals and target_goals read and remove_goal and remove_target_goal take (melee_attack). A species variant of a vanilla goal (a bee’s BeeHurtByOtherGoal) keeps its own vanilla name instead.

Trait Implementations§

§

impl Clone for GoalSpec

§

fn clone(&self) -> GoalSpec

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
§

impl Debug for GoalSpec

§

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

Formats the value using the given formatter. Read more
§

impl Wire for GoalSpec

§

const MIN: usize = 4usize

Minimum encoded size, used to reject impossible collection lengths.
§

fn put(&self, out: &mut Writer)

Encodes this value, recording failures on the writer.
§

fn put_owned(self, out: &mut Writer)

Consumes owned data when a resource’s ownership must cross the boundary.
§

fn take(input: &mut Reader<'_>) -> Result<GoalSpec, WireError>

Decodes one value, leaving any following bytes for the caller.

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<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.

§

impl<T> Put for T
where T: Wire,

§

fn put_to(&self, out: &mut Writer)

Writes it.
§

impl<T> Record for T
where T: Wire,

§

fn encode(&self, out: &mut Writer)

Writes the argument into a hook call.
§

fn apply(&mut self, bytes: &[u8]) -> Result<(), WireError>

Applies one complete reply, refusing malformed or trailing bytes atomically.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.