Skip to main content

MobRef

Struct MobRef 

pub struct MobRef(/* private fields */);
Expand description

A vanilla Mob, narrowed from an entity with host.mob(entity).

Implementations§

§

impl MobRef

pub fn goals(self, host: &dyn Host) -> Option<Vec<MobGoalEntry>>

Side: server. GoalSelector.getRunningGoals read wider: every goal of the goal selector as a MobGoalEntry (the priority, the kind id and whether it runs), in registration order. None for a stale or unavailable mob, a client, and the dragon.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn target_goals(self, host: &dyn Host) -> Option<Vec<MobGoalEntry>>

Side: server. Every goal of the target selector, as goals reads the goal selector’s.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn is_done(self, host: &dyn Host) -> Option<bool>

Side: server. PathNavigation.isDone; None for a stale or unavailable mob, or on a client, and for the dragon (no navigation).

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn navigation_speed(self, host: &dyn Host) -> Option<f64>

Side: server. PathNavigation.getSpeedModifier: the multiplier the current path is followed at (1.0 is the mob’s normal speed; 0 until a path sets one). This is not the mob’s movement-speed attribute. None for a stale or unavailable mob, or on a client, and for the dragon.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn pathfinding_malus(self, host: &dyn Host, kind: PathType) -> Option<f32>

Side: server. Mob.getPathfindingMalus: what a node of kind costs this mob’s pathfinder — its own override, else the kind’s default (a negative malus closes the kind). None for a stale or unavailable mob, the dragon, or on a client.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn can_use_portal(self, host: &dyn Host) -> Option<bool>

Side: both. The existing portal decision for an available mob in the current level.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn target(self, host: &dyn Host) -> Option<LivingRef>

Side: server. Mob.getTarget. Brain-backed mobs read their attack memory; piglins and hoglins use Horizon’s ai.target stand-in. Invalid targets, an unavailable mob or player binding, or a target without a living handle read as None. The dragon reads what a mod set, while it stays a valid target (EnderDragon.canAttack); its flight never sets one.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn is_aggressive(self, host: &dyn Host) -> Option<bool>

Side: server. Mob.isAggressive, the synced mob flag (the dragon’s reaches its clients as DATA_MOB_FLAGS_ID).

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn persistence_required(self, host: &dyn Host) -> Option<bool>

Side: server. Mob.isPersistenceRequired. The dragon never despawns (EnderDragon.checkDespawn is empty), but keeps and saves the flag (PersistenceRequired).

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn requires_custom_persistence(self, host: &dyn Host) -> Option<bool>

Side: server. Mob.requiresCustomPersistence and its species overrides: passengers, leashed mobs and species-specific reasons to stay, such as an enderman carrying a block. Independent of PersistenceRequired and NoAI. None for an unavailable mob or the separately modeled dragon.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn no_ai(self, host: &dyn Host) -> Option<bool>

Side: server. Mob.isNoAi: the mob stands where it is and its goals do not run, while what NoAI keeps running in vanilla (the daylight burn of the undead, a horse’s tail) still does. Saved with it as NoAI. None for anything but a mob.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn restrict_center(self, host: &dyn Host) -> Option<[i32; 3]>

Side: server. Mob.getRestrictCenter: the restriction’s block position, kept after clear_restriction and after a load ([0, 0, 0] for a mob that never had one, vanilla’s ZERO). None for a stale or unavailable mob, a client, and the dragon.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn restrict_radius(self, host: &dyn Host) -> Option<i32>

Side: server. Mob.getRestrictRadius: -1 while the mob has no restriction. None for a stale or unavailable mob, a client, and the dragon.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn has_restriction(self, host: &dyn Host) -> Option<bool>

Side: server. Mob.hasRestriction. None for a stale or unavailable mob, a client, and the dragon.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn is_within_restriction( self, host: &dyn Host, at: [i32; 3], ) -> Option<bool>

Side: server. Mob.isWithinRestriction(pos): whether the block position is inside the home area; a mob without a restriction is within everywhere, as in vanilla. None for a stale or unavailable mob, a client, and the dragon.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn left_handed(self, host: &dyn Host) -> Option<bool>

Side: server. Mob.isLeftHanded: whether the mob holds things in its left hand (the mob flags in its entity data). None for anything but a mob.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn can_pick_up_loot(self, host: &dyn Host) -> Option<bool>

Side: server. Mob.canPickUpLoot, with the overrides of an allay (holding something) and a sulfur cube (with no block). None for anything but a mob.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn no_action_time(self, host: &dyn Host) -> Option<i32>

Side: server. LivingEntity.getNoActionTime: the ticks since the mob last had a reason to stay (a player near, a hit). Despawning and a raid’s recruiting read it. None for a stale or unavailable mob, the dragon, or on a client.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn raid(self, host: &dyn Host) -> Option<RaidRef>

Side: server. Raider.getCurrentRaid: the raid a raider belongs to, even a stopped one. None for a mob that is no raider or in no raid.

In a mob’s goal tick (GoalContext::host) this reads the active mob or a disjoint live mob when available; player reads use the game host. Other unsupported reads retain their typed refusal.

pub fn add_goal( self, host: &mut dyn ServerHost, priority: i32, goal: &GoalSpec, ) -> bool

Side: server. GoalSelector.addGoal(priority, goal) on a mob’s goal selector. Refuses a stale or unavailable mob, a client, and the dragon (it keeps no selector); a goal the mob’s vanilla class does not hold (a PathfinderMob goal for a bat, ghast or phantom, BreedGoal or FollowParentGoal for a mob that is no animal); and non-finite numbers, negative speeds and distances, a probability outside 0..=1, a negative interval, and an unknown species id (in prey, what or only) or empty items. The target selector’s kinds (nearest_target, hurt_by_target) go in through add_target_goal; both selectors take them, as vanilla’s two selectors do.

pub fn add_target_goal( self, host: &mut dyn ServerHost, priority: i32, goal: &GoalSpec, ) -> bool

Side: server. GoalSelector.addGoal on the mob’s target selector. The same rules as add_goal.

pub fn remove_goal(self, host: &mut dyn ServerHost, id: &str) -> Option<usize>

Side: server. GoalSelector.removeGoal on the goal selector, by kind: every goal whose id, as goals reads it, is id goes (removeAllGoals), a running one stopped first. How many went; None for a stale or unavailable mob, a client, and the dragon. Nothing in a mob’s tick resolves, as its copy is held out there: add what a mod needs in entity_join, which fires for a loaded chunk’s mobs too.

pub fn remove_target_goal( self, host: &mut dyn ServerHost, id: &str, ) -> Option<usize>

Side: server. GoalSelector.removeGoal on the target selector, by kind, as remove_goal does on the goal selector.

pub fn move_to( self, host: &mut dyn ServerHost, at: [f64; 3], speed: f64, ) -> bool

Side: server. PathNavigation.moveTo(x, y, z, speed): true if a path was started. Refuses a stale or unavailable mob, a client, non-finite arguments, and coordinates too large for safe block arithmetic. As in vanilla, the mob’s own goals may replace the path next tick. False for the dragon, which flies by its phase and keeps no navigation.

pub fn stop(self, host: &mut dyn ServerHost) -> bool

Side: server. PathNavigation.stop. False for a stale or unavailable mob, or on a client, and for the dragon (no navigation).

pub fn set_navigation_speed(self, host: &mut dyn ServerHost, speed: f64) -> bool

Side: server. PathNavigation.setSpeedModifier: sets the multiplier the current path is followed at, as move_to‘s speed argument does. The mob’s own AI — a goal’s or a brain species’ next moveTo — sets its own again, as in vanilla. False for a non-finite speed, a stale or unavailable mob, or on a client, and for the dragon.

pub fn set_pathfinding_malus( self, host: &mut dyn ServerHost, kind: PathType, malus: f32, ) -> bool

Side: server. Mob.setPathfindingMalus: what the mob’s next paths cost through kind (negative closes it, as the species’ own overrides do); not saved, as in vanilla, so a reload or conversion keeps the species’ own. False for a malus that is not finite, a stale or unavailable mob, the dragon, or on a client.

pub fn set_target( self, host: &mut dyn ServerHost, target: Option<LivingRef>, ) -> bool

Side: server. Mob.setTarget; None clears it. Only mobs and players whose binding can be stored in the current level are supported; armor stands are refused. The dragon stores a mob or a player, which its flight ignores and its save does not keep (vanilla keeps no target either). Brain-backed mobs refuse writes: vanilla’s setter does not update their brain memory (#934). A fox, an enderman or a zombified piglin stores the target with its own setTarget side effects (Mob::set_target). Invalid targets are refused (false, mob unchanged); vanilla instead stores asValidTarget(target), clearing the target when it is invalid. False also means a stale handle, client, or an unavailable mob/player.

pub fn set_aggressive(self, host: &mut dyn ServerHost, value: bool) -> bool

Side: server. Mob.setAggressive. False for an unavailable mob.

pub fn set_persistence_required(self, host: &mut dyn ServerHost) -> bool

Side: server. Mob.setPersistenceRequired, which sets the flag and cannot clear it. False for an unavailable mob.

pub fn set_no_ai(self, host: &mut dyn ServerHost, no_ai: bool) -> bool

Side: server. Mob.setNoAi: whether the mob’s own AI runs. With no AI the mob stands (what NoAI keeps in vanilla still runs), and the flag is saved with it as NoAI. False for anything but a mob.

pub fn set_baby(self, host: &mut dyn ServerHost, baby: bool) -> bool

Side: server. Mob.setBaby through the species’ setter: ageable mobs use their baby start age (-48000 for sniffers, otherwise -24000) or 0, including age-boundary attribute and AI setup changes. Non-ageable babies, such as zombies, keep their non-growing baby state instead. Leaves NoAI and PersistenceRequired unchanged. False, with no changes, for an unavailable mob or a species with no baby form.

pub fn look_at(self, host: &mut dyn ServerHost, at: [f64; 3]) -> bool

Side: server. LookControl.setLookAt, by the mob’s lookAt path: the wanted position its look control rotates the head toward over the next ticks. As move_to‘s path, the mob’s own AI — a goal’s look, or a brain species’ LookAtTargetSink, which writes through this same control — may issue its own and replace this one; no species refuses. A creaking being looked at, an angry bee and an axolotl playing dead hold their look control, as in vanilla: the wanted position waits until it runs again. False for non-finite coordinates, a stale or unavailable mob, a client, and the dragon.

pub fn jump(self, host: &mut dyn ServerHost) -> bool

Side: server. JumpControl.jump: the mob jumps on its next own tick by its own jump path — no velocity is written, and the control consumes the wish on that tick (a rabbit’s jump control reads it too). The mob’s own wishes (a slime’s hop, a swimming brain’s) are the same flag; no species refuses. A creaking being looked at holds its jump control, as in vanilla: the wish waits until it runs again. False for a stale or unavailable mob, a client, and the dragon.

pub fn restrict_to( self, host: &mut dyn ServerHost, at: [i32; 3], radius: i32, ) -> bool

Side: server. Mob.restrictTo(pos, radius): the home area the mob keeps to — its own stroll and wander goals pick their positions inside it, as a lead’s and a guardian’s home do. Radius -1 clears the restriction while keeping pos as the center, clear_restriction’s shape. The area is saved with the mob (home_pos, home_radius). False for a stale or unavailable mob, a client, and the dragon.

pub fn clear_restriction(self, host: &mut dyn ServerHost) -> bool

Side: server. Mob.clearRestriction: the restriction goes, the center stays (its own goals read no restriction, as vanilla’s -1 radius). False for a stale or unavailable mob, a client, and the dragon.

pub fn set_left_handed( self, host: &mut dyn ServerHost, left_handed: bool, ) -> bool

Side: server. Mob.setLeftHanded: sets the mob flag the players around get with the mob’s next entity data and see in its swing and held items. Saved with the mob as LeftHanded. False for anything but a mob.

pub fn set_can_pick_up_loot( self, host: &mut dyn ServerHost, can_pick_up: bool, ) -> bool

Side: server. Mob.setCanPickUpLoot: whether the mob picks up the items it sees (saved with it as CanPickUpLoot; clients are not told, as in vanilla). An allay and a sulfur cube decide for themselves. False for anything but a mob.

pub fn set_no_action_time(self, host: &mut dyn ServerHost, ticks: i32) -> bool

Side: server. LivingEntity.setNoActionTime: the count the mob’s own tick carries on from (a far-away mob’s despawn chance starts past 600). Not saved, as in vanilla. False for a stale or unavailable mob, the dragon, or on a client.

pub fn set_brain_target( self, host: &mut dyn ServerHost, target: Option<LivingRef>, ) -> bool

Side: server. Brain.setMemory(ATTACK_TARGET, target), or eraseMemory for None: the target a brain-driven mob — an axolotl, a breeze, a creaking, a hoglin, a piglin or piglin brute, a warden or a zoglin — reads instead of Mob.setTarget‘s (#934). A plain, non-expiring memory write: the brain’s own behaviours act on it from the next tick (a target the species may not attack is dropped there, as vanilla’s StopAttackingIfTargetInvalid drops it), and none of a species’ own setter effects run — a warden’s setAttackTarget roar, reach and sonic-boom bookkeeping stays with its own sensing. A frog refuses: its target belongs to the running tongue attack, which starts from the nearest attackable, so a written one would not be pursued. False for a fake player, a player in another level, a mob without an attack-target brain (MobRef::set_target writes those), a stale or unavailable mob, the dragon, or on a client.

§

impl MobRef

pub fn entity(self) -> EntityRef

The same entity as an entity handle.

pub fn living(self) -> LivingRef

The same entity as a living handle.

Trait Implementations§

§

impl Clone for MobRef

§

fn clone(&self) -> MobRef

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 Copy for MobRef

§

impl Debug for MobRef

§

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

Formats the value using the given formatter. Read more
§

impl Eq for MobRef

§

impl Hash for MobRef

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for MobRef

§

fn eq(&self, other: &MobRef) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for MobRef

§

impl Wire for MobRef

§

const MIN: usize

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