From ef25e77e5262c68c682d889bc58e7120c66f978a Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 29 Jan 2025 02:00:44 +0000 Subject: [PATCH] add data for EntityEffect particle to fix set_entity_data errors on hypixel --- azalea-entity/src/particle.rs | 18 +++++++++++---- .../src/packets/game/c_set_entity_data.rs | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/azalea-entity/src/particle.rs b/azalea-entity/src/particle.rs index a8710effc..497f4cef9 100755 --- a/azalea-entity/src/particle.rs +++ b/azalea-entity/src/particle.rs @@ -8,7 +8,7 @@ use bevy_ecs::component::Component; // the order of this enum must be kept in sync with ParticleKind, otherwise // we get errors parsing particles. /// A [`ParticleKind`] with data potentially attached to it. -#[derive(Component, Clone, Debug, AzBuf, Default)] +#[derive(Component, Clone, Debug, AzBuf)] pub enum Particle { AngryVillager, Block(BlockParticle), @@ -30,8 +30,7 @@ pub enum Particle { EnchantedHit, Enchant, EndRod, - #[default] - EntityEffect, + EntityEffect(ColorParticle), ExplosionEmitter, Explosion, Gust, @@ -154,7 +153,7 @@ impl From for Particle { ParticleKind::EnchantedHit => Self::EnchantedHit, ParticleKind::Enchant => Self::Enchant, ParticleKind::EndRod => Self::EndRod, - ParticleKind::EntityEffect => Self::EntityEffect, + ParticleKind::EntityEffect => Self::EntityEffect(ColorParticle::default()), ParticleKind::ExplosionEmitter => Self::ExplosionEmitter, ParticleKind::Explosion => Self::Explosion, ParticleKind::Gust => Self::Gust, @@ -250,6 +249,12 @@ impl From for Particle { } } +impl Default for Particle { + fn default() -> Self { + Self::EntityEffect(ColorParticle::default()) + } +} + #[derive(Debug, Clone, AzBuf, Default)] pub struct BlockParticle { pub block_state: BlockState, @@ -269,6 +274,11 @@ pub struct DustColorTransitionParticle { pub scale: f32, } +#[derive(Debug, Clone, AzBuf, Default)] +pub struct ColorParticle { + pub color: RgbColor, +} + #[derive(Debug, Clone, AzBuf, Default)] pub struct ItemParticle { pub item: ItemStack, diff --git a/azalea-protocol/src/packets/game/c_set_entity_data.rs b/azalea-protocol/src/packets/game/c_set_entity_data.rs index da6536fe5..769c2edfd 100755 --- a/azalea-protocol/src/packets/game/c_set_entity_data.rs +++ b/azalea-protocol/src/packets/game/c_set_entity_data.rs @@ -8,3 +8,26 @@ pub struct ClientboundSetEntityData { pub id: u32, pub packed_items: EntityMetadataItems, } + +#[cfg(test)] +mod tests { + use std::io::Cursor; + + use azalea_buf::AzaleaRead; + + use super::*; + + #[test] + fn test_read_write_container_set_content() { + let contents = [161, 226, 1, 10, 18, 1, 20, 38, 124, 175, 198, 255]; + let mut buf = Cursor::new(contents.as_slice()); + let packet = ClientboundSetEntityData::azalea_read(&mut buf).unwrap(); + println!("{:?}", packet); + + assert_eq!(buf.position(), contents.len() as u64); + + let mut buf = Vec::new(); + packet.write(&mut buf).unwrap(); + assert_eq!(buf, contents); + } +}