From dec544a52ba738e2d0e2c3a042e5ccc0cb336ffb Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 15 Aug 2024 01:24:03 +0000 Subject: [PATCH] fix ClientboundLevelParticlesPacket errors and pathfinder /particle errors --- azalea-entity/src/particle.rs | 56 +++++++++---------- .../clientbound_level_particles_packet.rs | 22 ++++++++ azalea/build.rs | 2 +- azalea/src/pathfinder/debug.rs | 4 +- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/azalea-entity/src/particle.rs b/azalea-entity/src/particle.rs index 6d8c9fd9b..ab8ac5bbe 100755 --- a/azalea-entity/src/particle.rs +++ b/azalea-entity/src/particle.rs @@ -4,30 +4,19 @@ use azalea_inventory::ItemSlot; use azalea_registry::ParticleKind; use bevy_ecs::component::Component; -#[derive(Component, Debug, Clone, McBuf, Default)] -pub struct Particle { - #[var] - pub id: i32, - pub data: ParticleData, -} - -#[derive(Clone, Debug, McBuf, Default)] -pub enum ParticleData { +// 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, McBuf, Default)] +pub enum Particle { AngryVillager, - BlockMarker(BlockParticle), Block(BlockParticle), + BlockMarker(BlockParticle), Bubble, - BubbleColumnUp, - BubblePop, - CampfireCosySmoke, - CampfireSignalSmoke, Cloud, - Composter, Crit, - CurrentDown, DamageIndicator, DragonBreath, - Dolphin, DrippingLava, FallingLava, LandingLava, @@ -44,33 +33,35 @@ pub enum ParticleData { EntityEffect, ExplosionEmitter, Explosion, - SonicBoom, - FallingDust(BlockParticle), Gust, SmallGust, GustEmitterLarge, GustEmitterSmall, + SonicBoom, + FallingDust(BlockParticle), Firework, Fishing, Flame, Infested, + CherryLeaves, SculkSoul, SculkCharge(SculkChargeParticle), SculkChargePop, - Soul, SoulFireFlame, + Soul, Flash, HappyVillager, + Composter, Heart, InstantEffect, Item(ItemParticle), + Vibration(VibrationParticle), ItemSlime, ItemCobweb, ItemSnowball, LargeSmoke, Lava, Mycelium, - Nautilus, Note, Poof, Portal, @@ -78,35 +69,40 @@ pub enum ParticleData { Smoke, WhiteSmoke, Sneeze, - Snowflake, Spit, + SquidInk, SweepAttack, TotemOfUndying, - SquidInk, Underwater, Splash, Witch, + BubblePop, + CurrentDown, + BubbleColumnUp, + Nautilus, + Dolphin, + CampfireCosySmoke, + CampfireSignalSmoke, DrippingHoney, FallingHoney, LandingHoney, FallingNectar, FallingSporeBlossom, - SporeBlossomAir, Ash, CrimsonSpore, WarpedSpore, + SporeBlossomAir, DrippingObsidianTear, FallingObsidianTear, LandingObsidianTear, ReversePortal, WhiteAsh, SmallFlame, - DrippingDripstoneWater, - FallingDripstoneWater, - CherryLeaves, + Snowflake, DrippingDripstoneLava, FallingDripstoneLava, - Vibration(VibrationParticle), + DrippingDripstoneWater, + FallingDripstoneWater, GlowSquidInk, Glow, WaxOn, @@ -120,12 +116,12 @@ pub enum ParticleData { TrialSpawnerDetectionOminous, VaultConnection, DustPillar, + OminousSpawning, RaidOmen, TrialOmen, - OminousSpawning, } -impl From for ParticleData { +impl From for Particle { /// Convert a particle kind into particle data. If the particle has data /// attached (like block particles), then it's set to the default. fn from(kind: ParticleKind) -> Self { diff --git a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs index b543d4f0a..eae996347 100755 --- a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs @@ -15,3 +15,25 @@ pub struct ClientboundLevelParticlesPacket { pub count: u32, pub particle: Particle, } + +#[cfg(test)] +mod tests { + use std::io::Cursor; + + use azalea_buf::McBufReadable; + + use super::*; + + #[test] + fn test_clientbound_level_particles_packet() { + let slice = &[ + 0, 64, 139, 10, 0, 0, 0, 0, 0, 192, 26, 0, 0, 0, 0, 0, 0, 64, 144, 58, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 13, 63, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 63, 128, 0, 0, + ][..]; + let mut bytes = Cursor::new(slice); + + let _packet = ClientboundLevelParticlesPacket::read_from(&mut bytes).unwrap(); + assert_eq!(bytes.position(), slice.len() as u64); + } +} diff --git a/azalea/build.rs b/azalea/build.rs index 6fe004841..9a5037496 100644 --- a/azalea/build.rs +++ b/azalea/build.rs @@ -7,7 +7,7 @@ fn main() { // stable & beta panic!("Azalea currently requires nightly Rust. You can use `rustup override set nightly` to set the toolchain for this directory."); } - Ok(_) => return, // nightly + Ok(_) => {} // nightly Err(_) => { // probably not installed via rustup, run rustc and parse its output let rustc_command = env::var("RUSTC") diff --git a/azalea/src/pathfinder/debug.rs b/azalea/src/pathfinder/debug.rs index 201803c9b..a5e51cdf9 100644 --- a/azalea/src/pathfinder/debug.rs +++ b/azalea/src/pathfinder/debug.rs @@ -55,8 +55,6 @@ pub fn debug_render_path_with_particles( let mut start = executing_path.last_reached_node; for (i, movement) in executing_path.path.iter().enumerate() { - // /particle dust 0 1 1 1 ~ ~ ~ 0 0 0.2 0 100 - let end = movement.target; let start_vec3 = start.center(); @@ -91,7 +89,7 @@ pub fn debug_render_path_with_particles( z: start_vec3.z + (end_vec3.z - start_vec3.z) * percent, }; let particle_command = format!( - "/particle dust {r} {g} {b} {size} {start_x} {start_y} {start_z} {delta_x} {delta_y} {delta_z} 0 {count}", + "/particle dust{{color:[{r},{g},{b}],scale:{size}}} {start_x} {start_y} {start_z} {delta_x} {delta_y} {delta_z} 0 {count}", size = 1, start_x = pos.x, start_y = pos.y,