Skip to main content

LivingEntityBase

Struct LivingEntityBase 

Source
pub struct LivingEntityBase {
    state: SyncMutex<LivingEntityState>,
    attributes: SyncMutex<AttributeMap>,
    active_mob_effects: SyncMutex<FxHashMap<MobEffectRef, ActiveMobEffect>>,
    dirty_mob_effects: SyncMutex<Vec<MobEffectSyncChange>>,
    equipment: Shared<dyn EntityEquipment>,
    last_equipment_items: SyncMutex<[ItemStack; 8]>,
    pending_equipment_changes: SyncMutex<[Option<ItemStack>; 8]>,
    equipment_attribute_modifiers: SyncMutex<[Vec<EquipmentAttributeModifierKey>; 8]>,
}
Expand description

Common runtime fields shared by all living entities.

Deviation from vanilla: Vanilla calls this guard LivingEntity.dead, but it means death side effects have been processed, not health is zero. ServerPlayer.die() does NOT call super.die() and never sets that field. Steel uses this guard for players too because it reuses the same Player instance; health remains the source of truth for dead-or-dying checks such as client respawn requests.

Fields§

§state: SyncMutex<LivingEntityState>§attributes: SyncMutex<AttributeMap>§active_mob_effects: SyncMutex<FxHashMap<MobEffectRef, ActiveMobEffect>>§dirty_mob_effects: SyncMutex<Vec<MobEffectSyncChange>>§equipment: Shared<dyn EntityEquipment>§last_equipment_items: SyncMutex<[ItemStack; 8]>§pending_equipment_changes: SyncMutex<[Option<ItemStack>; 8]>§equipment_attribute_modifiers: SyncMutex<[Vec<EquipmentAttributeModifierKey>; 8]>

Implementations§

Source§

impl LivingEntityBase

Source

pub fn new(entity_type: EntityTypeRef) -> Self

Creates living runtime state from an entity type’s default attributes.

Source

pub fn with_attributes(attributes: AttributeMap) -> Self

Creates living runtime state from an explicit attribute map.

Source

pub fn with_equipment( entity_type: EntityTypeRef, equipment: Shared<dyn EntityEquipment>, ) -> Self

Creates living runtime state with an explicit canonical equipment backing.

Source

fn with_attributes_and_equipment( attributes: AttributeMap, equipment: Shared<dyn EntityEquipment>, ) -> Self

Source

pub const fn attributes(&self) -> &SyncMutex<AttributeMap>

Returns this entity’s attribute map.

Source

pub fn initialize_synced_data<T: VanillaLivingEntityData>( &self, entity_data: &mut T, )

Applies vanilla constructor-time synced-data mutations for living entities.

Vanilla defines DATA_HEALTH_ID as 1.0F, then LivingEntity constructs its attribute map and calls setHealth(getMaxHealth()).

Source

pub const fn equipment(&self) -> &Shared<dyn EntityEquipment>

Returns vanilla LivingEntity.equipment storage.

Source

pub fn collect_equipment_changes( &self, ) -> Vec<(EquipmentSlot, ItemStack, ItemStack)>

Collects equipment changes against Vanilla’s previous-tick snapshots.

Source

pub fn queue_equipment_changes( &self, changes: impl IntoIterator<Item = (EquipmentSlot, ItemStack)>, )

Coalesces detected equipment changes until entity tracking sends them.

Source

pub fn drain_equipment_changes(&self) -> Vec<(EquipmentSlot, ItemStack)>

Drains equipment changes detected by the living tick.

Source

pub fn rotation_state(&self) -> LivingRotationState

Returns vanilla living body/head rotation state.

Source

pub fn swing_state(&self) -> LivingSwingState

Returns vanilla arm-swing animation state.

Source

pub fn y_body_rot(&self) -> f32

Returns vanilla yBodyRot.

Source

pub fn set_y_body_rot(&self, y_body_rot: f32)

Sets vanilla yBodyRot.

Source

pub fn y_head_rot(&self) -> f32

Returns vanilla yHeadRot.

Source

pub fn set_y_head_rot(&self, y_head_rot: f32)

Sets vanilla yHeadRot.

Source

pub fn advance_rotation_for_base_tick(&self)

Copies current living head/body rotations to their old-rotation fields.

Source

pub fn advance_attack_animation_for_base_tick(&self)

Copies current attack animation to vanilla oAttackAnim.

Source

pub fn start_swing( &self, hand: InteractionHand, current_swing_duration: i32, ) -> bool

Starts vanilla LivingEntity.swing state if the swing gate allows it.

Source

pub fn update_swing_time(&self, current_swing_duration: i32)

Updates vanilla LivingEntity.swingTime and attackAnim.

Source

pub fn absorption_amount(&self) -> f32

Returns vanilla LivingEntity.absorptionAmount for non-player living entities.

Source

pub fn set_absorption_amount(&self, amount: f32)

Sets vanilla LivingEntity.absorptionAmount for non-player living entities.

Source

pub fn skip_drop_experience(&self)

Runs vanilla LivingEntity.skipDropExperience.

Source

pub fn was_experience_consumed(&self) -> bool

Returns vanilla LivingEntity.wasExperienceConsumed.

Source

pub fn no_action_time(&self) -> i32

Returns vanilla LivingEntity.noActionTime.

Source

pub fn set_no_action_time(&self, no_action_time: i32)

Sets vanilla LivingEntity.noActionTime.

Source

pub fn increment_no_action_time(&self)

Increments vanilla LivingEntity.noActionTime by one tick.

Source

pub fn refresh_equipment_attribute_modifiers( &self, slot: EquipmentSlot, item_stack: &ItemStack, )

Refreshes transient item attribute modifiers for an equipment slot.

Source

pub fn has_mob_effect(&self, effect: MobEffectRef) -> bool

Returns whether this living entity has an active vanilla mob effect.

Source

pub fn mob_effect(&self, effect: MobEffectRef) -> Option<ActiveMobEffect>

Returns active vanilla mob-effect state.

Source

pub fn active_mob_effects(&self) -> Vec<ActiveMobEffect>

Returns all active vanilla mob effects.

Source

pub fn add_mob_effect(&self, effect: MobEffectInstance) -> bool

Adds or updates active vanilla mob-effect state.

Source

pub fn set_mob_effect(&self, effect: MobEffectRef, amplifier: i32)

Sets active vanilla mob-effect state.

Source

pub fn set_mob_effect_active(&self, effect: MobEffectRef, active: bool)

Sets the presence of a vanilla mob effect.

Source

pub fn remove_mob_effect(&self, effect: MobEffectRef) -> bool

Removes active vanilla mob-effect state.

Source

pub(super) fn tick_mob_effect_duration(&self, effect_key: MobEffectRef)

Ticks one active mob-effect duration after its server behavior has run.

Source

pub fn drain_dirty_mob_effects(&self) -> Vec<MobEffectSyncChange>

Drains pending mob-effect packet changes.

Source

pub fn take_effects_dirty(&self) -> bool

Returns whether synchronized effect entity data should be recomputed.

Source

pub fn mob_effect_display_state(&self) -> MobEffectDisplayState

Builds the synchronized living effect particle/glow/invisibility state.

Source

fn add_effect_attribute_modifiers(&self, effect: &MobEffectInstance)

Source

fn refresh_effect_attribute_modifiers(&self, effect: &MobEffectInstance)

Source

fn remove_effect_attribute_modifiers(&self, effect: MobEffectRef)

Source

fn queue_mob_effect_sync(&self, change: MobEffectSyncChange)

Source

pub(crate) fn mark_effects_dirty(&self)

Marks synchronized effect visibility data for recomputation.

Source

pub fn speed(&self) -> f32

Gets the cached movement speed used by living movement code.

Source

pub fn set_speed(&self, speed: f32)

Sets the cached movement speed used by living movement code.

Source

pub fn refresh_speed_from_attributes(&self)

Refreshes the cached movement speed from the MOVEMENT_SPEED attribute.

Source

pub fn apply_post_impulse_grace_time(&self, ticks: i32)

Applies vanilla post-impulse movement validation grace.

Source

pub fn set_ignore_fall_damage_from_current_impulse( &self, ignore_fall_damage: bool, new_impulse_impact_pos: DVec3, )

Mirrors vanilla LivingEntity.setIgnoreFallDamageFromCurrentImpulse.

Source

pub fn current_impulse_impact_pos(&self) -> Option<DVec3>

Returns vanilla LivingEntity.currentImpulseImpactPos.

Source

pub fn current_impulse_context_reset_grace_time(&self) -> i32

Returns vanilla LivingEntity.currentImpulseContextResetGraceTime.

Source

pub fn is_ignoring_fall_damage_from_current_impulse(&self) -> bool

Returns vanilla LivingEntity.isIgnoringFallDamageFromCurrentImpulse.

Source

pub fn try_reset_current_impulse_context(&self)

Mirrors vanilla LivingEntity.tryResetCurrentImpulseContext.

Source

pub fn reset_current_impulse_context(&self)

Mirrors vanilla LivingEntity.resetCurrentImpulseContext.

Source

pub fn is_in_post_impulse_grace_time(&self) -> bool

Returns whether movement validation is inside post-impulse grace.

Source

pub fn tick_post_impulse_grace_time(&self)

Decrements post-impulse grace once per living-entity tick.

Source

pub fn is_fall_flying(&self) -> bool

Returns whether this living entity is currently fall flying.

Source

pub fn set_fall_flying(&self, fall_flying: bool)

Sets the vanilla living-entity fall-flying state.

Source

pub fn fall_flying_ticks(&self) -> i32

Returns vanilla LivingEntity.fallFlyTicks.

Source

pub fn tick_fall_flying_state(&self, fall_flying: bool)

Ticks vanilla LivingEntity.fallFlyTicks.

Source

pub fn is_sprinting(&self) -> bool

Returns whether this living entity is sprinting.

Source

pub fn set_sprinting(&self, sprinting: bool)

Sets the vanilla living-entity sprinting state and movement-speed modifier.

Source

pub fn sleeping_pos(&self) -> Option<BlockPos>

Returns the bed position that makes this living entity sleeping.

Source

pub fn set_sleeping_pos(&self, bed_position: BlockPos)

Sets the vanilla living-entity sleeping position.

Source

pub fn clear_sleeping_pos(&self)

Clears the vanilla living-entity sleeping position.

Source

pub fn is_sleeping(&self) -> bool

Returns whether this living entity has a sleeping position.

Source

pub fn last_climbable_pos(&self) -> Option<BlockPos>

Returns the last climbable block position this living entity touched.

Source

pub fn set_last_climbable_pos(&self, pos: BlockPos)

Records the last climbable block position this living entity touched.

Source

pub fn should_discard_friction(&self) -> bool

Returns whether vanilla living travel should skip friction damping.

Source

pub fn set_discard_friction(&self, discard_friction: bool)

Sets whether vanilla living travel should skip friction damping.

Source

pub fn is_jumping(&self) -> bool

Returns whether this living entity is applying jump input.

Source

pub fn set_jumping(&self, jumping: bool)

Sets whether this living entity is applying jump input.

Source

pub fn travel_input(&self) -> LivingTravelInput

Returns vanilla living travel input.

Source

pub fn set_travel_input(&self, input: LivingTravelInput)

Sets vanilla living travel input.

Source

pub fn dampen_travel_input(&self)

Applies vanilla LivingEntity.applyInput() damping to travel input.

Source

pub fn no_jump_delay(&self) -> i32

Returns vanilla jump cooldown ticks.

Source

pub fn set_no_jump_delay(&self, ticks: i32)

Sets vanilla jump cooldown ticks.

Source

pub fn tick_no_jump_delay(&self)

Decrements vanilla jump cooldown once per living AI step.

Source

pub fn calculate_fall_damage( fall_distance: f64, damage_modifier: f32, safe_fall_distance: f64, fall_damage_multiplier: f64, ) -> i32

Calculates vanilla living-entity fall damage.

Source

pub fn decrement_invulnerable_time(&self)

Decrements remaining invulnerability ticks by one if any are active.

Source

pub fn apply_damage_cooldown( &self, amount: f32, bypasses_cooldown: bool, ) -> Option<(bool, f32)>

Applies vanilla hurt cooldown bookkeeping.

Returns None when damage should be ignored because death was already processed or the amount did not exceed the active invulnerability frame.

Source

pub fn record_last_damage_source(&self, source: &DamageSource, game_time: i64)

Records vanilla LivingEntity.lastDamageSource after successful damage.

Source

pub fn last_damage_source(&self, game_time: i64) -> Option<DamageSource>

Returns vanilla LivingEntity.getLastDamageSource().

Source

pub fn set_last_hurt_by_player(&self, player_uuid: Uuid, time_to_remember: i32)

Sets vanilla LivingEntity.lastHurtByPlayer and memory time.

Source

pub fn last_hurt_by_player_memory_time(&self) -> i32

Returns vanilla LivingEntity.lastHurtByPlayerMemoryTime.

Source

pub fn last_hurt_by_player_uuid(&self) -> Option<Uuid>

Returns the remembered player UUID, if present.

Source

pub fn last_hurt_by_mob(&self) -> Option<SharedEntity>

Returns vanilla LivingEntity.lastHurtByMob, if still resolvable.

Source

pub fn last_hurt_by_mob_timestamp(&self) -> i32

Returns vanilla LivingEntity.lastHurtByMobTimestamp.

Source

pub fn set_last_hurt_by_mob( &self, target: Option<&SharedEntity>, tick_count: i32, )

Sets vanilla LivingEntity.lastHurtByMob and timestamp.

Source

pub fn last_hurt_mob(&self) -> Option<SharedEntity>

Returns vanilla LivingEntity.lastHurtMob, if still resolvable.

Source

pub fn last_hurt_mob_timestamp(&self) -> i32

Returns vanilla LivingEntity.lastHurtMobTimestamp.

Source

pub fn set_last_hurt_mob(&self, target: Option<&SharedEntity>, tick_count: i32)

Sets vanilla LivingEntity.lastHurtMob and timestamp.

Source

pub fn tick_last_hurt_by_player_memory(&self)

Ticks vanilla last-hurt-by-player memory.

Source

pub fn tick_living_combat_memory(&self, tick_count: i32)

Ticks vanilla living combat-memory cleanup.

Source

pub fn mark_death_processed(&self) -> bool

Marks death side effects as processed.

Returns false if they were already processed.

Source

pub fn increment_death_time(&self) -> i32

Increments death animation time by 1 and returns the new value.

Source

pub fn death_time(&self) -> i32

Returns vanilla LivingEntity.deathTime.

Source

pub fn reset_death_state(&self)

Resets all death-related state back to alive defaults.

Source

pub fn reset_for_player_respawn(&self)

Resets state that vanilla gets from constructing a fresh living player for death respawn.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more