Skip to content

Commit

Permalink
fix ClientboundLevelParticlesPacket errors and pathfinder /particle e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
mat-1 committed Aug 15, 2024
1 parent 13afc1d commit dec544a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
56 changes: 26 additions & 30 deletions azalea-entity/src/particle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -44,69 +33,76 @@ 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,
Rain,
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,
Expand All @@ -120,12 +116,12 @@ pub enum ParticleData {
TrialSpawnerDetectionOminous,
VaultConnection,
DustPillar,
OminousSpawning,
RaidOmen,
TrialOmen,
OminousSpawning,
}

impl From<ParticleKind> for ParticleData {
impl From<ParticleKind> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion azalea/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions azalea/src/pathfinder/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dec544a

Please sign in to comment.