Skip to main content

steel_core/entity/mob_effect/
mod.rs

1//! Mob-effect behaviors: one small module per vanilla `MobEffect` subtype
2//! under `net/minecraft/world/effect`.
3
4mod absorption;
5mod bad_omen;
6mod heal_or_harm;
7mod hunger;
8mod infested;
9mod oozing;
10mod poison;
11mod raid_omen;
12mod regeneration;
13mod saturation;
14mod weaving;
15mod wind_charged;
16mod wither;
17
18pub use absorption::AbsorptionBehavior;
19pub use bad_omen::BadOmenBehavior;
20pub use heal_or_harm::HealOrHarmBehavior;
21pub use hunger::HungerBehavior;
22pub use infested::InfestedBehavior;
23pub use oozing::OozingBehavior;
24pub use poison::PoisonBehavior;
25pub use raid_omen::RaidOmenBehavior;
26pub use regeneration::RegenerationBehavior;
27pub use saturation::SaturationBehavior;
28pub use weaving::WeavingBehavior;
29pub use wind_charged::WindChargedBehavior;
30pub use wither::WitherBehavior;
31
32use crate::entity::LivingEntity;
33use crate::world::World;
34
35/// One vanilla `MobEffect` subtype's runtime behavior. Default methods match
36/// vanilla's own `MobEffect` base-class defaults, so an effect with no
37/// registered behavior (most of them) behaves exactly like a bare vanilla
38/// `MobEffect` instance.
39pub trait MobEffectBehavior: Send + Sync {
40    /// Returns the instantaneous-only half of this behavior, if any.
41    fn as_instantaneous(&self) -> Option<&dyn InstantaneousMobEffect> {
42        None
43    }
44
45    /// Mirrors vanilla `MobEffect.shouldApplyEffectTickThisTick`.
46    fn should_apply_effect_tick_this_tick(&self, tick_count: i32, _amplifier: i32) -> bool {
47        self.as_instantaneous().is_some() && tick_count >= 1
48    }
49
50    /// Mirrors vanilla `MobEffect.applyEffectTick`. Returns whether the
51    /// effect remains active.
52    fn apply_effect_tick(&self, _world: &World, _user: &dyn LivingEntity, _amplifier: i32) -> bool {
53        true
54    }
55
56    /// Mirrors vanilla `MobEffect.onEffectStarted`.
57    fn on_effect_started(&self, _user: &dyn LivingEntity, _amplifier: i32) {}
58}
59
60/// The instantaneous-only half of a [`MobEffectBehavior`] that also extends
61/// vanilla `InstantaneousMobEffect`.
62pub trait InstantaneousMobEffect: MobEffectBehavior {
63    /// Mirrors vanilla `InstantaneousMobEffect`'s override of
64    /// `applyInstantaneousEffect`.
65    fn apply_instantaneous(
66        &self,
67        world: &World,
68        user: &dyn LivingEntity,
69        amplifier: i32,
70        direct_entity: Option<i32>,
71        causing_entity: Option<i32>,
72        scale: f32,
73    ) {
74        let _ = (direct_entity, causing_entity, scale);
75        self.apply_effect_tick(world, user, amplifier);
76    }
77}