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 so repeated callbacks cannot duplicate
death side effects. 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
impl LivingEntityBase
Sourcepub fn new(entity_type: EntityTypeRef) -> Self
pub fn new(entity_type: EntityTypeRef) -> Self
Creates living runtime state from an entity type’s default attributes.
Sourcepub fn with_attributes(attributes: AttributeMap) -> Self
pub fn with_attributes(attributes: AttributeMap) -> Self
Creates living runtime state from an explicit attribute map.
Sourcepub fn with_equipment(
entity_type: EntityTypeRef,
equipment: Shared<dyn EntityEquipment>,
) -> Self
pub fn with_equipment( entity_type: EntityTypeRef, equipment: Shared<dyn EntityEquipment>, ) -> Self
Creates living runtime state with an explicit canonical equipment backing.
fn with_attributes_and_equipment( attributes: AttributeMap, equipment: Shared<dyn EntityEquipment>, ) -> Self
Sourcepub const fn attributes(&self) -> &SyncMutex<AttributeMap>
pub const fn attributes(&self) -> &SyncMutex<AttributeMap>
Returns this entity’s attribute map.
Sourcepub fn initialize_synced_data<T: VanillaLivingEntityData>(
&self,
entity_data: &mut T,
)
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()).
Sourcepub const fn equipment(&self) -> &Shared<dyn EntityEquipment>
pub const fn equipment(&self) -> &Shared<dyn EntityEquipment>
Returns this entity’s equipped-item storage.
Sourcepub fn collect_equipment_changes(
&self,
) -> Vec<(EquipmentSlot, ItemStack, ItemStack)>
pub fn collect_equipment_changes( &self, ) -> Vec<(EquipmentSlot, ItemStack, ItemStack)>
Collects equipment changes against Vanilla’s previous-tick snapshots.
Sourcepub fn queue_equipment_changes(
&self,
changes: impl IntoIterator<Item = (EquipmentSlot, ItemStack)>,
)
pub fn queue_equipment_changes( &self, changes: impl IntoIterator<Item = (EquipmentSlot, ItemStack)>, )
Coalesces detected equipment changes until entity tracking sends them.
Sourcepub fn drain_equipment_changes(&self) -> Vec<(EquipmentSlot, ItemStack)>
pub fn drain_equipment_changes(&self) -> Vec<(EquipmentSlot, ItemStack)>
Drains equipment changes detected by the living tick.
Sourcepub fn rotation_state(&self) -> LivingRotationState
pub fn rotation_state(&self) -> LivingRotationState
Returns vanilla living body/head rotation state.
Sourcepub fn swing_state(&self) -> LivingSwingState
pub fn swing_state(&self) -> LivingSwingState
Returns vanilla arm-swing animation state.
Sourcepub fn active_item_use(&self) -> Option<ActiveItemUseState>
pub fn active_item_use(&self) -> Option<ActiveItemUseState>
Returns a snapshot of vanilla active item-use state.
Sourcepub fn is_using_item(&self) -> bool
pub fn is_using_item(&self) -> bool
Returns whether this living entity is actively using an item.
Sourcepub fn start_using_item(
&self,
hand: InteractionHand,
item: &ItemStack,
duration: i32,
) -> bool
pub fn start_using_item( &self, hand: InteractionHand, item: &ItemStack, duration: i32, ) -> bool
Starts vanilla active item use.
Sourcepub fn stop_using_item(&self) -> Option<ActiveItemUseState>
pub fn stop_using_item(&self) -> Option<ActiveItemUseState>
Stops vanilla active item use without calling item hooks.
Sourcepub fn decrement_active_item_use(&self) -> Option<ActiveItemUseState>
pub fn decrement_active_item_use(&self) -> Option<ActiveItemUseState>
Decrements active-use remaining ticks and returns the updated state.
Sourcepub fn y_body_rot(&self) -> f32
pub fn y_body_rot(&self) -> f32
Returns the entity’s body yaw, used for turning smoothing separate from head yaw.
Sourcepub fn set_y_body_rot(&self, y_body_rot: f32)
pub fn set_y_body_rot(&self, y_body_rot: f32)
Sets the entity’s body yaw.
Sourcepub fn y_head_rot(&self) -> f32
pub fn y_head_rot(&self) -> f32
Returns the entity’s head yaw.
Sourcepub fn set_y_head_rot(&self, y_head_rot: f32)
pub fn set_y_head_rot(&self, y_head_rot: f32)
Sets the entity’s head yaw.
Sourcepub fn advance_rotation_for_base_tick(&self)
pub fn advance_rotation_for_base_tick(&self)
Copies current living head/body rotations to their old-rotation fields.
Sourcepub fn start_swing(
&self,
hand: InteractionHand,
animation: SwingAnimation,
duration_ticks: i32,
) -> bool
pub fn start_swing( &self, hand: InteractionHand, animation: SwingAnimation, duration_ticks: i32, ) -> bool
Starts a swing when the active animation’s restart gate allows it.
Sourcepub fn tick_swing_state(&self)
pub fn tick_swing_state(&self)
Advances the swing animation at the start of the living entity’s base tick.
Sourcepub fn absorption_amount(&self) -> f32
pub fn absorption_amount(&self) -> f32
Returns vanilla LivingEntity.absorptionAmount for non-player living entities.
Sourcepub fn set_absorption_amount(&self, amount: f32)
pub fn set_absorption_amount(&self, amount: f32)
Sets vanilla LivingEntity.absorptionAmount for non-player living entities.
Sourcepub fn skip_drop_experience(&self)
pub fn skip_drop_experience(&self)
Marks this entity to skip dropping experience on death.
Sourcepub fn was_experience_consumed(&self) -> bool
pub fn was_experience_consumed(&self) -> bool
Returns whether this entity has been marked to skip dropping experience.
Sourcepub fn no_action_time(&self) -> i32
pub fn no_action_time(&self) -> i32
Returns ticks this entity has gone without taking a noteworthy action.
Sourcepub fn set_no_action_time(&self, no_action_time: i32)
pub fn set_no_action_time(&self, no_action_time: i32)
Sets ticks this entity has gone without taking a noteworthy action.
Sourcepub fn increment_no_action_time(&self)
pub fn increment_no_action_time(&self)
Increments the no-action-time counter by one tick.
Sourcepub fn refresh_equipment_attribute_modifiers(
&self,
slot: EquipmentSlot,
item_stack: &ItemStack,
)
pub fn refresh_equipment_attribute_modifiers( &self, slot: EquipmentSlot, item_stack: &ItemStack, )
Refreshes transient item attribute modifiers for an equipment slot.
Sourcepub fn has_mob_effect(&self, effect: MobEffectRef) -> bool
pub fn has_mob_effect(&self, effect: MobEffectRef) -> bool
Returns whether this living entity has an active vanilla mob effect.
Sourcepub fn mob_effect(&self, effect: MobEffectRef) -> Option<ActiveMobEffect>
pub fn mob_effect(&self, effect: MobEffectRef) -> Option<ActiveMobEffect>
Returns active vanilla mob-effect state.
Sourcepub fn active_mob_effects(&self) -> Vec<ActiveMobEffect> ⓘ
pub fn active_mob_effects(&self) -> Vec<ActiveMobEffect> ⓘ
Returns all active vanilla mob effects.
Sourcepub fn add_mob_effect(&self, effect: MobEffectInstance) -> bool
pub fn add_mob_effect(&self, effect: MobEffectInstance) -> bool
Adds or updates active vanilla mob-effect state.
Sourcepub fn set_mob_effect(&self, effect: MobEffectRef, amplifier: i32)
pub fn set_mob_effect(&self, effect: MobEffectRef, amplifier: i32)
Sets active vanilla mob-effect state.
Sourcepub fn set_mob_effect_active(&self, effect: MobEffectRef, active: bool)
pub fn set_mob_effect_active(&self, effect: MobEffectRef, active: bool)
Sets the presence of a vanilla mob effect.
Sourcepub fn remove_mob_effect(&self, effect: MobEffectRef) -> bool
pub fn remove_mob_effect(&self, effect: MobEffectRef) -> bool
Removes active vanilla mob-effect state.
Sourcepub(super) fn tick_mob_effect_duration(&self, effect_key: MobEffectRef)
pub(super) fn tick_mob_effect_duration(&self, effect_key: MobEffectRef)
Ticks one active mob-effect duration after its server behavior has run.
Sourcepub fn drain_dirty_mob_effects(&self) -> Vec<MobEffectSyncChange>
pub fn drain_dirty_mob_effects(&self) -> Vec<MobEffectSyncChange>
Drains pending mob-effect packet changes.
Sourcepub fn take_effects_dirty(&self) -> bool
pub fn take_effects_dirty(&self) -> bool
Returns whether synchronized effect entity data should be recomputed.
Sourcepub fn mob_effect_display_state(&self) -> MobEffectDisplayState
pub fn mob_effect_display_state(&self) -> MobEffectDisplayState
Builds the synchronized living effect particle/glow/invisibility state.
fn add_effect_attribute_modifiers(&self, effect: &MobEffectInstance)
fn refresh_effect_attribute_modifiers(&self, effect: &MobEffectInstance)
fn remove_effect_attribute_modifiers(&self, effect: MobEffectRef)
fn queue_mob_effect_sync(&self, change: MobEffectSyncChange)
Sourcepub(crate) fn mark_effects_dirty(&self)
pub(crate) fn mark_effects_dirty(&self)
Marks synchronized effect visibility data for recomputation.
Sourcepub fn set_speed(&self, speed: f32)
pub fn set_speed(&self, speed: f32)
Sets the cached movement speed used by living movement code.
Sourcepub fn refresh_speed_from_attributes(&self)
pub fn refresh_speed_from_attributes(&self)
Refreshes the cached movement speed from the MOVEMENT_SPEED attribute.
Sourcepub fn apply_post_impulse_grace_time(&self, ticks: i32)
pub fn apply_post_impulse_grace_time(&self, ticks: i32)
Applies vanilla post-impulse movement validation grace.
Sourcepub fn set_ignore_fall_damage_from_current_impulse(
&self,
ignore_fall_damage: bool,
new_impulse_impact_pos: DVec3,
)
pub fn set_ignore_fall_damage_from_current_impulse( &self, ignore_fall_damage: bool, new_impulse_impact_pos: DVec3, )
Sets whether fall damage from the current knockback/impulse impact should be ignored.
Sourcepub fn current_impulse_impact_pos(&self) -> Option<DVec3>
pub fn current_impulse_impact_pos(&self) -> Option<DVec3>
Returns the position of the most recent knockback/impulse impact, if still active.
Sourcepub fn current_impulse_context_reset_grace_time(&self) -> i32
pub fn current_impulse_context_reset_grace_time(&self) -> i32
Returns ticks remaining before the current impulse context can be reset.
Sourcepub fn is_ignoring_fall_damage_from_current_impulse(&self) -> bool
pub fn is_ignoring_fall_damage_from_current_impulse(&self) -> bool
Returns whether fall damage should be ignored due to a recent knockback/impulse impact.
Sourcepub fn try_reset_current_impulse_context(&self)
pub fn try_reset_current_impulse_context(&self)
Clears the current impulse impact position once its grace time has expired.
Sourcepub fn reset_current_impulse_context(&self)
pub fn reset_current_impulse_context(&self)
Immediately clears the current impulse impact position and its grace time.
Sourcepub fn is_in_post_impulse_grace_time(&self) -> bool
pub fn is_in_post_impulse_grace_time(&self) -> bool
Returns whether movement validation is inside post-impulse grace.
Sourcepub fn tick_post_impulse_grace_time(&self)
pub fn tick_post_impulse_grace_time(&self)
Decrements post-impulse grace once per living-entity tick.
Sourcepub fn is_fall_flying(&self) -> bool
pub fn is_fall_flying(&self) -> bool
Returns whether this living entity is currently fall flying.
Sourcepub fn set_fall_flying(&self, fall_flying: bool)
pub fn set_fall_flying(&self, fall_flying: bool)
Sets the vanilla living-entity fall-flying state.
Sourcepub fn fall_flying_ticks(&self) -> i32
pub fn fall_flying_ticks(&self) -> i32
Returns ticks this entity has been fall-flying (elytra gliding).
Sourcepub fn tick_fall_flying_state(&self, fall_flying: bool)
pub fn tick_fall_flying_state(&self, fall_flying: bool)
Advances (or resets) the fall-flying tick counter based on whether the entity is currently fall-flying.
Sourcepub fn is_sprinting(&self) -> bool
pub fn is_sprinting(&self) -> bool
Returns whether this living entity is sprinting.
Sourcepub fn set_sprinting(&self, sprinting: bool)
pub fn set_sprinting(&self, sprinting: bool)
Sets the vanilla living-entity sprinting state and movement-speed modifier.
Sourcepub fn sleeping_pos(&self) -> Option<BlockPos>
pub fn sleeping_pos(&self) -> Option<BlockPos>
Returns the bed position that makes this living entity sleeping.
Sourcepub fn set_sleeping_pos(&self, bed_position: BlockPos)
pub fn set_sleeping_pos(&self, bed_position: BlockPos)
Sets the vanilla living-entity sleeping position.
Sourcepub fn clear_sleeping_pos(&self)
pub fn clear_sleeping_pos(&self)
Clears the vanilla living-entity sleeping position.
Sourcepub fn is_sleeping(&self) -> bool
pub fn is_sleeping(&self) -> bool
Returns whether this living entity has a sleeping position.
Sourcepub fn last_climbable_pos(&self) -> Option<BlockPos>
pub fn last_climbable_pos(&self) -> Option<BlockPos>
Returns the last climbable block position this living entity touched.
Sourcepub fn set_last_climbable_pos(&self, pos: BlockPos)
pub fn set_last_climbable_pos(&self, pos: BlockPos)
Records the last climbable block position this living entity touched.
Sourcepub fn should_discard_friction(&self) -> bool
pub fn should_discard_friction(&self) -> bool
Returns whether vanilla living travel should skip friction damping.
Sourcepub fn set_discard_friction(&self, discard_friction: bool)
pub fn set_discard_friction(&self, discard_friction: bool)
Sets whether vanilla living travel should skip friction damping.
Sourcepub fn is_jumping(&self) -> bool
pub fn is_jumping(&self) -> bool
Returns whether this living entity is applying jump input.
Sourcepub fn set_jumping(&self, jumping: bool)
pub fn set_jumping(&self, jumping: bool)
Sets whether this living entity is applying jump input.
Sourcepub fn travel_input(&self) -> LivingTravelInput
pub fn travel_input(&self) -> LivingTravelInput
Returns vanilla living travel input.
Sourcepub fn set_travel_input(&self, input: LivingTravelInput)
pub fn set_travel_input(&self, input: LivingTravelInput)
Sets vanilla living travel input.
Sourcepub fn dampen_travel_input(&self)
pub fn dampen_travel_input(&self)
Applies horizontal damping to the stored travel input.
Sourcepub fn no_jump_delay(&self) -> i32
pub fn no_jump_delay(&self) -> i32
Returns vanilla jump cooldown ticks.
Sourcepub fn set_no_jump_delay(&self, ticks: i32)
pub fn set_no_jump_delay(&self, ticks: i32)
Sets vanilla jump cooldown ticks.
Sourcepub fn tick_no_jump_delay(&self)
pub fn tick_no_jump_delay(&self)
Decrements vanilla jump cooldown once per living AI step.
Sourcepub fn calculate_fall_damage(
fall_distance: f64,
damage_modifier: f32,
safe_fall_distance: f64,
fall_damage_multiplier: f64,
) -> i32
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.
Sourcepub fn invulnerable_time(&self) -> i32
pub fn invulnerable_time(&self) -> i32
Returns the remaining hurt-cooldown ticks.
Sourcepub fn set_invulnerable_time(&self, invulnerable_time: i32)
pub fn set_invulnerable_time(&self, invulnerable_time: i32)
Sets the remaining hurt-cooldown ticks.
Sourcepub fn decrement_invulnerable_time(&self)
pub fn decrement_invulnerable_time(&self)
Decrements remaining invulnerability ticks by one if any are active.
Sourcepub fn begin_hurt_animation(&self)
pub fn begin_hurt_animation(&self)
Starts the vanilla hurt animation.
Sourcepub fn decrement_hurt_time(&self)
pub fn decrement_hurt_time(&self)
Decrements the vanilla hurt animation timer.
Sourcepub fn hurt_duration(&self) -> i32
pub fn hurt_duration(&self) -> i32
Returns the current hurt duration
Sourcepub fn apply_damage_cooldown(
&self,
amount: f32,
bypasses_cooldown: bool,
) -> Option<(bool, f32)>
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.
Sourcepub fn set_last_hurt_by_player(&self, player_uuid: Uuid, time_to_remember: i32)
pub fn set_last_hurt_by_player(&self, player_uuid: Uuid, time_to_remember: i32)
Records the player that last hurt this entity, remembered for
time_to_remember ticks.
Sourcepub fn set_last_hurt_by_player_memory_time(&self, time_to_remember: i32)
pub fn set_last_hurt_by_player_memory_time(&self, time_to_remember: i32)
Sets the remaining memory time without touching the remembered player.
Sourcepub(crate) fn set_last_hurt_by_player_entity(
&self,
player: &SharedEntity,
time_to_remember: i32,
)
pub(crate) fn set_last_hurt_by_player_entity( &self, player: &SharedEntity, time_to_remember: i32, )
Remembers the live player independently of which world it occupies.
Sourcepub(crate) fn last_hurt_by_player(&self, world: &World) -> Option<SharedEntity>
pub(crate) fn last_hurt_by_player(&self, world: &World) -> Option<SharedEntity>
Resolves cached kill credit before falling back to the saved UUID.
Sourcepub fn last_hurt_by_player_memory_time(&self) -> i32
pub fn last_hurt_by_player_memory_time(&self) -> i32
Returns ticks remaining that this entity will remember the player who last hurt it.
Sourcepub fn last_hurt_by_player_uuid(&self) -> Option<Uuid>
pub fn last_hurt_by_player_uuid(&self) -> Option<Uuid>
Returns the remembered player UUID, if present.
Sourcepub fn last_hurt_by_mob(&self) -> Option<SharedEntity>
pub fn last_hurt_by_mob(&self) -> Option<SharedEntity>
Returns vanilla LivingEntity.lastHurtByMob, if still resolvable.
Sourcepub fn last_hurt_by_mob_timestamp(&self) -> i32
pub fn last_hurt_by_mob_timestamp(&self) -> i32
Returns the tick timestamp this entity was last hurt by a mob.
Sourcepub fn set_last_hurt_by_mob(
&self,
target: Option<&SharedEntity>,
tick_count: i32,
)
pub fn set_last_hurt_by_mob( &self, target: Option<&SharedEntity>, tick_count: i32, )
Records the mob that last hurt this entity and the tick it happened.
Sourcepub fn last_hurt_mob(&self) -> Option<SharedEntity>
pub fn last_hurt_mob(&self) -> Option<SharedEntity>
Returns vanilla LivingEntity.lastHurtMob, if still resolvable.
Sourcepub fn last_hurt_mob_timestamp(&self) -> i32
pub fn last_hurt_mob_timestamp(&self) -> i32
Returns the tick timestamp this entity last hurt a mob.
Sourcepub fn set_last_hurt_mob(&self, target: Option<&SharedEntity>, tick_count: i32)
pub fn set_last_hurt_mob(&self, target: Option<&SharedEntity>, tick_count: i32)
Records the mob this entity last hurt and the tick it happened.
Sourcepub fn tick_last_hurt_by_player_memory(&self)
pub fn tick_last_hurt_by_player_memory(&self)
Ticks vanilla last-hurt-by-player memory.
Sourcepub fn tick_living_combat_memory(&self, tick_count: i32)
pub fn tick_living_combat_memory(&self, tick_count: i32)
Ticks vanilla living combat-memory cleanup.
Sourcepub fn is_death_processed(&self) -> bool
pub fn is_death_processed(&self) -> bool
Returns whether death side effects have already run.
Close to vanilla LivingEntity.dead, which guards die, but not identical:
Steel also gates Self::apply_damage_cooldown on it, and players set it
through their own death path. Treat it as “this entity has already died”,
not as a faithful mirror of the vanilla field.
Sourcepub fn mark_death_processed(&self) -> bool
pub fn mark_death_processed(&self) -> bool
Marks death side effects as processed.
Returns false if they were already processed.
Sourcepub fn increment_death_time(&self) -> i32
pub fn increment_death_time(&self) -> i32
Increments death animation time by 1 and returns the new value.
Sourcepub fn death_time(&self) -> i32
pub fn death_time(&self) -> i32
Returns ticks elapsed since this entity started dying (its death animation).
Sourcepub fn reset_death_state(&self)
pub fn reset_death_state(&self)
Resets all death-related state back to alive defaults.
Auto Trait Implementations§
impl !Freeze for LivingEntityBase
impl !RefUnwindSafe for LivingEntityBase
impl !UnwindSafe for LivingEntityBase
impl Send for LivingEntityBase
impl Sync for LivingEntityBase
impl Unpin for LivingEntityBase
impl UnsafeUnpin for LivingEntityBase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreArc<SyncMutex<>>