diff options
| author | ShayBox <shaybox@shaybox.com> | 2025-10-30 12:14:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-30 11:14:19 -0500 |
| commit | 818f2d01d49e574946d1a704e1445156afc9c2fb (patch) | |
| tree | 4190ce61994e7d1280cbcd6b43811fa9f6b03b09 /azalea-protocol/src/packets | |
| parent | c7cc381fae569f3dfc9f2abe86c2c38d59b68cf2 (diff) | |
| download | azalea-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-protocol/src/packets')
| -rw-r--r-- | azalea-protocol/src/packets/game/c_update_mob_effect.rs | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/azalea-protocol/src/packets/game/c_update_mob_effect.rs b/azalea-protocol/src/packets/game/c_update_mob_effect.rs index 201589fb..896d547b 100644 --- a/azalea-protocol/src/packets/game/c_update_mob_effect.rs +++ b/azalea-protocol/src/packets/game/c_update_mob_effect.rs @@ -1,4 +1,6 @@ -use azalea_buf::AzBuf; +use std::io::{Cursor, Write}; + +use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::MobEffect; use azalea_world::MinecraftEntityId; @@ -12,5 +14,39 @@ pub struct ClientboundUpdateMobEffect { pub effect_amplifier: u32, #[var] pub effect_duration_ticks: u32, - pub flags: u8, + pub flags: MobEffectFlags, +} + +#[derive(Clone, Debug, Default, PartialEq)] +pub struct MobEffectFlags { + pub ambient: bool, + pub show_particles: bool, + pub show_icon: bool, +} + +impl AzaleaRead for MobEffectFlags { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let bits = u8::azalea_read(buf)?; + Ok(MobEffectFlags { + ambient: bits & 0x01 != 0, + show_particles: bits & 0x02 != 0, + show_icon: bits & 0x04 != 0, + }) + } +} + +impl AzaleaWrite for MobEffectFlags { + fn azalea_write(&self, buf: &mut impl Write) -> std::io::Result<()> { + let mut bits = 0; + if self.ambient { + bits |= 0x01; + } + if self.show_particles { + bits |= 0x02; + } + if self.show_icon { + bits |= 0x04; + } + bits.azalea_write(buf) + } } |
