Skip to main content

steel_core/entity/mob_effect/
wither.rs

1//! `WitherMobEffect` behavior.
2
3use steel_registry::vanilla_damage_types;
4
5use super::MobEffectBehavior;
6use crate::entity::LivingEntity;
7use crate::entity::damage::DamageSource;
8use crate::world::World;
9
10const DAMAGE_INTERVAL: i32 = 40;
11
12/// Mirrors vanilla `WitherMobEffect`.
13pub struct WitherBehavior;
14
15impl MobEffectBehavior for WitherBehavior {
16    fn should_apply_effect_tick_this_tick(&self, tick_count: i32, amplifier: i32) -> bool {
17        let interval = DAMAGE_INTERVAL.wrapping_shr(amplifier as u32);
18        interval <= 0 || tick_count % interval == 0
19    }
20
21    fn apply_effect_tick(&self, world: &World, user: &dyn LivingEntity, _amplifier: i32) -> bool {
22        user.hurt(
23            world,
24            &DamageSource::environment(&vanilla_damage_types::WITHER),
25            1.0,
26        );
27        true
28    }
29}