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
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 vanilla LivingEntity.equipment 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 y_body_rot(&self) -> f32
pub fn y_body_rot(&self) -> f32
Returns vanilla yBodyRot.
Sourcepub fn set_y_body_rot(&self, y_body_rot: f32)
pub fn set_y_body_rot(&self, y_body_rot: f32)
Sets vanilla yBodyRot.
Sourcepub fn y_head_rot(&self) -> f32
pub fn y_head_rot(&self) -> f32
Returns vanilla yHeadRot.
Sourcepub fn set_y_head_rot(&self, y_head_rot: f32)
pub fn set_y_head_rot(&self, y_head_rot: f32)
Sets vanilla yHeadRot.
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 advance_attack_animation_for_base_tick(&self)
pub fn advance_attack_animation_for_base_tick(&self)
Copies current attack animation to vanilla oAttackAnim.
Sourcepub fn start_swing(
&self,
hand: InteractionHand,
current_swing_duration: i32,
) -> bool
pub fn start_swing( &self, hand: InteractionHand, current_swing_duration: i32, ) -> bool
Starts vanilla LivingEntity.swing state if the swing gate allows it.
Sourcepub fn update_swing_time(&self, current_swing_duration: i32)
pub fn update_swing_time(&self, current_swing_duration: i32)
Updates vanilla LivingEntity.swingTime and attackAnim.
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)
Runs vanilla LivingEntity.skipDropExperience.
Sourcepub fn was_experience_consumed(&self) -> bool
pub fn was_experience_consumed(&self) -> bool
Returns vanilla LivingEntity.wasExperienceConsumed.
Sourcepub fn no_action_time(&self) -> i32
pub fn no_action_time(&self) -> i32
Returns vanilla LivingEntity.noActionTime.
Sourcepub fn set_no_action_time(&self, no_action_time: i32)
pub fn set_no_action_time(&self, no_action_time: i32)
Sets vanilla LivingEntity.noActionTime.
Sourcepub fn increment_no_action_time(&self)
pub fn increment_no_action_time(&self)
Increments vanilla LivingEntity.noActionTime 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, )
Mirrors vanilla LivingEntity.setIgnoreFallDamageFromCurrentImpulse.
Sourcepub fn current_impulse_impact_pos(&self) -> Option<DVec3>
pub fn current_impulse_impact_pos(&self) -> Option<DVec3>
Returns vanilla LivingEntity.currentImpulseImpactPos.
Sourcepub fn current_impulse_context_reset_grace_time(&self) -> i32
pub fn current_impulse_context_reset_grace_time(&self) -> i32
Returns vanilla LivingEntity.currentImpulseContextResetGraceTime.
Sourcepub fn is_ignoring_fall_damage_from_current_impulse(&self) -> bool
pub fn is_ignoring_fall_damage_from_current_impulse(&self) -> bool
Returns vanilla LivingEntity.isIgnoringFallDamageFromCurrentImpulse.
Sourcepub fn try_reset_current_impulse_context(&self)
pub fn try_reset_current_impulse_context(&self)
Mirrors vanilla LivingEntity.tryResetCurrentImpulseContext.
Sourcepub fn reset_current_impulse_context(&self)
pub fn reset_current_impulse_context(&self)
Mirrors vanilla LivingEntity.resetCurrentImpulseContext.
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 vanilla LivingEntity.fallFlyTicks.
Sourcepub fn tick_fall_flying_state(&self, fall_flying: bool)
pub fn tick_fall_flying_state(&self, fall_flying: bool)
Ticks vanilla LivingEntity.fallFlyTicks.
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 vanilla LivingEntity.applyInput() damping to 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 decrement_invulnerable_time(&self)
pub fn decrement_invulnerable_time(&self)
Decrements remaining invulnerability ticks by one if any are active.
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 record_last_damage_source(&self, source: &DamageSource, game_time: i64)
pub fn record_last_damage_source(&self, source: &DamageSource, game_time: i64)
Records vanilla LivingEntity.lastDamageSource after successful damage.
Sourcepub fn last_damage_source(&self, game_time: i64) -> Option<DamageSource>
pub fn last_damage_source(&self, game_time: i64) -> Option<DamageSource>
Returns vanilla LivingEntity.getLastDamageSource().
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)
Sets vanilla LivingEntity.lastHurtByPlayer and memory time.
Sourcepub fn last_hurt_by_player_memory_time(&self) -> i32
pub fn last_hurt_by_player_memory_time(&self) -> i32
Returns vanilla LivingEntity.lastHurtByPlayerMemoryTime.
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 vanilla LivingEntity.lastHurtByMobTimestamp.
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, )
Sets vanilla LivingEntity.lastHurtByMob and timestamp.
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 vanilla LivingEntity.lastHurtMobTimestamp.
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)
Sets vanilla LivingEntity.lastHurtMob and timestamp.
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 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 vanilla LivingEntity.deathTime.
Sourcepub fn reset_death_state(&self)
pub fn reset_death_state(&self)
Resets all death-related state back to alive defaults.
Sourcepub fn reset_for_player_respawn(&self)
pub fn reset_for_player_respawn(&self)
Resets state that vanilla gets from constructing a fresh living player for death respawn.
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<>>