Skip to main content

steel_core/entity/mob_effect/
absorption.rs

1//! `AbsorptionMobEffect` behavior.
2
3use super::MobEffectBehavior;
4use crate::entity::LivingEntity;
5use crate::world::World;
6
7/// Mirrors vanilla `AbsorptionMobEffect`: expires once absorption hearts run
8/// out, rather than on a duration timer.
9pub struct AbsorptionBehavior;
10
11/// Absorption HP granted per amplifier level (vanilla `4.0F`).
12const ABSORPTION_PER_LEVEL: f32 = 4.0;
13
14impl MobEffectBehavior for AbsorptionBehavior {
15    fn should_apply_effect_tick_this_tick(&self, _tick_count: i32, _amplifier: i32) -> bool {
16        true
17    }
18
19    fn apply_effect_tick(&self, _world: &World, user: &dyn LivingEntity, _amplifier: i32) -> bool {
20        user.get_absorption_amount() > 0.0
21    }
22
23    /// Grants `4 * (1 + amplifier)` absorption hearts, never lowering an
24    /// existing higher amount.
25    fn on_effect_started(&self, user: &dyn LivingEntity, amplifier: i32) {
26        let amount = ABSORPTION_PER_LEVEL * (1 + amplifier) as f32;
27        user.set_absorption_amount(user.get_absorption_amount().max(amount));
28    }
29}