aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src/effects.rs
diff options
context:
space:
mode:
authorShayBox <shaybox@shaybox.com>2025-10-30 12:14:19 -0400
committerGitHub <noreply@github.com>2025-10-30 11:14:19 -0500
commit818f2d01d49e574946d1a704e1445156afc9c2fb (patch)
tree4190ce61994e7d1280cbcd6b43811fa9f6b03b09 /azalea-entity/src/effects.rs
parentc7cc381fae569f3dfc9f2abe86c2c38d59b68cf2 (diff)
downloadazalea-drasl-818f2d01d49e574946d1a704e1445156afc9c2fb.tar.xz
Add support for mob effects (#269)
* Add support for mob effects * Remove Option * MobEffectFlags * jump_boost_power f32
Diffstat (limited to 'azalea-entity/src/effects.rs')
-rw-r--r--azalea-entity/src/effects.rs83
1 files changed, 71 insertions, 12 deletions
diff --git a/azalea-entity/src/effects.rs b/azalea-entity/src/effects.rs
index 9cc750e5..d905414d 100644
--- a/azalea-entity/src/effects.rs
+++ b/azalea-entity/src/effects.rs
@@ -1,21 +1,80 @@
-// TODO
+use std::collections::HashMap;
-// pub struct ActiveEffects(HashMap<azalea_registry::MobEffect, MobEffectData>);
+use azalea_registry::MobEffect;
+use bevy_ecs::component::Component;
-/// Returns the level of the given effect, or `None` if the effect is not
-/// active. The lowest level is 0.
-pub fn get_effect(_effect: azalea_registry::MobEffect) -> Option<u32> {
- // TODO
- None
+/// Data about an active mob effect that the client knows about.
+#[derive(Clone, Debug, Default)]
+pub struct MobEffectData {
+ pub amplifier: u32,
+ pub duration_ticks: u32,
+ pub ambient: bool,
+ pub show_particles: bool,
+ pub show_icon: bool,
+}
+impl MobEffectData {
+ pub fn new(
+ amplifier: u32,
+ duration_ticks: u32,
+ ambient: bool,
+ show_particles: bool,
+ show_icon: bool,
+ ) -> Self {
+ Self {
+ amplifier,
+ duration_ticks,
+ ambient,
+ show_particles,
+ show_icon,
+ }
+ }
+
+ pub fn is_ambient(&self) -> bool {
+ self.ambient
+ }
+ pub fn should_show_particles(&self) -> bool {
+ self.show_particles
+ }
+ pub fn should_show_icon(&self) -> bool {
+ self.show_icon
+ }
+}
+
+/// Component storing the active mob effects on an entity.
+#[derive(Component, Clone, Debug, Default)]
+pub struct ActiveEffects(pub HashMap<MobEffect, MobEffectData>);
+impl ActiveEffects {
+ pub fn insert(&mut self, effect: MobEffect, data: MobEffectData) {
+ self.0.insert(effect, data);
+ }
+
+ pub fn remove(&mut self, effect: MobEffect) -> Option<MobEffectData> {
+ self.0.remove(&effect)
+ }
+
+ pub fn get_level(&self, effect: MobEffect) -> Option<u32> {
+ self.0.get(&effect).map(|data| data.amplifier)
+ }
+
+ pub fn get(&self, effect: MobEffect) -> Option<&MobEffectData> {
+ self.0.get(&effect)
+ }
+}
+
+/// Returns the level (amplifier) of the given effect, or `None` if the effect
+/// is not active. The lowest level is 0.
+pub fn get_effect(active_effects: &ActiveEffects, effect: MobEffect) -> Option<u32> {
+ active_effects.get_level(effect)
}
-pub fn get_dig_speed_amplifier() -> Option<u32> {
+/// Returns the amplifier for dig speed (haste / conduit power), if present.
+pub fn get_dig_speed_amplifier(active_effects: &ActiveEffects) -> Option<u32> {
let effect_plus_one = u32::max(
- get_effect(azalea_registry::MobEffect::Haste)
- .map(|x| x + 1)
+ get_effect(active_effects, MobEffect::Haste)
+ .map(|level| level + 1)
.unwrap_or_default(),
- get_effect(azalea_registry::MobEffect::ConduitPower)
- .map(|x| x + 1)
+ get_effect(active_effects, MobEffect::ConduitPower)
+ .map(|level| level + 1)
.unwrap_or_default(),
);
if effect_plus_one > 0 {