feat: add level particles event
This commit is contained in:
		| @@ -2,7 +2,8 @@ use crate::{ | |||||||
|     State, |     State, | ||||||
|     commands::CommandSource, |     commands::CommandSource, | ||||||
|     http::serve, |     http::serve, | ||||||
|     lua::{self, player::Player}, |     lua::{self, player::Player, vec3::Vec3}, | ||||||
|  |     particle, | ||||||
| }; | }; | ||||||
| use azalea::{prelude::*, protocol::packets::game::ClientboundGamePacket}; | use azalea::{prelude::*, protocol::packets::game::ClientboundGamePacket}; | ||||||
| use hyper::{server::conn::http1, service::service_fn}; | use hyper::{server::conn::http1, service::service_fn}; | ||||||
| @@ -69,12 +70,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow: | |||||||
|             call_listeners(&state, "update_player", Player::from(player_info)).await; |             call_listeners(&state, "update_player", Player::from(player_info)).await; | ||||||
|         } |         } | ||||||
|         Event::Packet(packet) => match packet.as_ref() { |         Event::Packet(packet) => match packet.as_ref() { | ||||||
|             ClientboundGamePacket::SetPassengers(packet) => { |  | ||||||
|                 let table = state.lua.create_table()?; |  | ||||||
|                 table.set("vehicle", packet.vehicle)?; |  | ||||||
|                 table.set("passengers", &*packet.passengers)?; |  | ||||||
|                 call_listeners(&state, "set_passengers", table).await; |  | ||||||
|             } |  | ||||||
|             ClientboundGamePacket::SetHealth(packet) => { |             ClientboundGamePacket::SetHealth(packet) => { | ||||||
|                 let table = state.lua.create_table()?; |                 let table = state.lua.create_table()?; | ||||||
|                 table.set("food", packet.food)?; |                 table.set("food", packet.food)?; | ||||||
| @@ -82,6 +77,19 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow: | |||||||
|                 table.set("saturation", packet.saturation)?; |                 table.set("saturation", packet.saturation)?; | ||||||
|                 call_listeners(&state, "set_health", table).await; |                 call_listeners(&state, "set_health", table).await; | ||||||
|             } |             } | ||||||
|  |             ClientboundGamePacket::SetPassengers(packet) => { | ||||||
|  |                 let table = state.lua.create_table()?; | ||||||
|  |                 table.set("vehicle", packet.vehicle)?; | ||||||
|  |                 table.set("passengers", &*packet.passengers)?; | ||||||
|  |                 call_listeners(&state, "set_passengers", table).await; | ||||||
|  |             } | ||||||
|  |             ClientboundGamePacket::LevelParticles(packet) => { | ||||||
|  |                 let table = state.lua.create_table()?; | ||||||
|  |                 table.set("position", Vec3::from(packet.pos))?; | ||||||
|  |                 table.set("count", packet.count)?; | ||||||
|  |                 table.set("kind", particle::to_kind(&packet.particle) as u8)?; | ||||||
|  |                 call_listeners(&state, "level_particles", table).await; | ||||||
|  |             } | ||||||
|             _ => (), |             _ => (), | ||||||
|         }, |         }, | ||||||
|         Event::Init => { |         Event::Init => { | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ mod commands; | |||||||
| mod events; | mod events; | ||||||
| mod http; | mod http; | ||||||
| mod lua; | mod lua; | ||||||
|  | mod particle; | ||||||
|  |  | ||||||
| use azalea::{ | use azalea::{ | ||||||
|     DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*, |     DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*, | ||||||
|   | |||||||
							
								
								
									
										119
									
								
								src/particle.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								src/particle.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,119 @@ | |||||||
|  | use azalea::{entity::particle::Particle, registry::ParticleKind}; | ||||||
|  |  | ||||||
|  | #[allow(clippy::too_many_lines)] | ||||||
|  | pub fn to_kind(particle: &Particle) -> ParticleKind { | ||||||
|  |     match particle { | ||||||
|  |         Particle::AngryVillager => ParticleKind::AngryVillager, | ||||||
|  |         Particle::Block(_) => ParticleKind::Block, | ||||||
|  |         Particle::BlockMarker(_) => ParticleKind::BlockMarker, | ||||||
|  |         Particle::Bubble => ParticleKind::Bubble, | ||||||
|  |         Particle::Cloud => ParticleKind::Cloud, | ||||||
|  |         Particle::Crit => ParticleKind::Crit, | ||||||
|  |         Particle::DamageIndicator => ParticleKind::DamageIndicator, | ||||||
|  |         Particle::DragonBreath => ParticleKind::DragonBreath, | ||||||
|  |         Particle::DrippingLava => ParticleKind::DrippingLava, | ||||||
|  |         Particle::FallingLava => ParticleKind::FallingLava, | ||||||
|  |         Particle::LandingLava => ParticleKind::LandingLava, | ||||||
|  |         Particle::DrippingWater => ParticleKind::DrippingWater, | ||||||
|  |         Particle::FallingWater => ParticleKind::FallingWater, | ||||||
|  |         Particle::Dust(_) => ParticleKind::Dust, | ||||||
|  |         Particle::DustColorTransition(_) => ParticleKind::DustColorTransition, | ||||||
|  |         Particle::Effect => ParticleKind::Effect, | ||||||
|  |         Particle::ElderGuardian => ParticleKind::ElderGuardian, | ||||||
|  |         Particle::EnchantedHit => ParticleKind::EnchantedHit, | ||||||
|  |         Particle::Enchant => ParticleKind::Enchant, | ||||||
|  |         Particle::EndRod => ParticleKind::EndRod, | ||||||
|  |         Particle::EntityEffect(_) => ParticleKind::EntityEffect, | ||||||
|  |         Particle::ExplosionEmitter => ParticleKind::ExplosionEmitter, | ||||||
|  |         Particle::Explosion => ParticleKind::Explosion, | ||||||
|  |         Particle::Gust => ParticleKind::Gust, | ||||||
|  |         Particle::SonicBoom => ParticleKind::SonicBoom, | ||||||
|  |         Particle::FallingDust(_) => ParticleKind::FallingDust, | ||||||
|  |         Particle::Firework => ParticleKind::Firework, | ||||||
|  |         Particle::Fishing => ParticleKind::Fishing, | ||||||
|  |         Particle::Flame => ParticleKind::Flame, | ||||||
|  |         Particle::CherryLeaves => ParticleKind::CherryLeaves, | ||||||
|  |         Particle::PaleOakLeaves => ParticleKind::PaleOakLeaves, | ||||||
|  |         Particle::SculkSoul => ParticleKind::SculkSoul, | ||||||
|  |         Particle::SculkCharge(_) => ParticleKind::SculkCharge, | ||||||
|  |         Particle::SculkChargePop => ParticleKind::SculkChargePop, | ||||||
|  |         Particle::SoulFireFlame => ParticleKind::SoulFireFlame, | ||||||
|  |         Particle::Soul => ParticleKind::Soul, | ||||||
|  |         Particle::Flash => ParticleKind::Flash, | ||||||
|  |         Particle::HappyVillager => ParticleKind::HappyVillager, | ||||||
|  |         Particle::Composter => ParticleKind::Composter, | ||||||
|  |         Particle::Heart => ParticleKind::Heart, | ||||||
|  |         Particle::InstantEffect => ParticleKind::InstantEffect, | ||||||
|  |         Particle::Item(_) => ParticleKind::Item, | ||||||
|  |         Particle::Vibration(_) => ParticleKind::Vibration, | ||||||
|  |         Particle::ItemSlime => ParticleKind::ItemSlime, | ||||||
|  |         Particle::ItemSnowball => ParticleKind::ItemSnowball, | ||||||
|  |         Particle::LargeSmoke => ParticleKind::LargeSmoke, | ||||||
|  |         Particle::Lava => ParticleKind::Lava, | ||||||
|  |         Particle::Mycelium => ParticleKind::Mycelium, | ||||||
|  |         Particle::Note => ParticleKind::Note, | ||||||
|  |         Particle::Poof => ParticleKind::Poof, | ||||||
|  |         Particle::Portal => ParticleKind::Portal, | ||||||
|  |         Particle::Rain => ParticleKind::Rain, | ||||||
|  |         Particle::Smoke => ParticleKind::Smoke, | ||||||
|  |         Particle::WhiteSmoke => ParticleKind::WhiteSmoke, | ||||||
|  |         Particle::Sneeze => ParticleKind::Sneeze, | ||||||
|  |         Particle::Spit => ParticleKind::Spit, | ||||||
|  |         Particle::SquidInk => ParticleKind::SquidInk, | ||||||
|  |         Particle::SweepAttack => ParticleKind::SweepAttack, | ||||||
|  |         Particle::TotemOfUndying => ParticleKind::TotemOfUndying, | ||||||
|  |         Particle::Underwater => ParticleKind::Underwater, | ||||||
|  |         Particle::Splash => ParticleKind::Splash, | ||||||
|  |         Particle::Witch => ParticleKind::Witch, | ||||||
|  |         Particle::BubblePop => ParticleKind::BubblePop, | ||||||
|  |         Particle::CurrentDown => ParticleKind::CurrentDown, | ||||||
|  |         Particle::BubbleColumnUp => ParticleKind::BubbleColumnUp, | ||||||
|  |         Particle::Nautilus => ParticleKind::Nautilus, | ||||||
|  |         Particle::Dolphin => ParticleKind::Dolphin, | ||||||
|  |         Particle::CampfireCosySmoke => ParticleKind::CampfireCosySmoke, | ||||||
|  |         Particle::CampfireSignalSmoke => ParticleKind::CampfireSignalSmoke, | ||||||
|  |         Particle::DrippingHoney => ParticleKind::DrippingHoney, | ||||||
|  |         Particle::FallingHoney => ParticleKind::FallingHoney, | ||||||
|  |         Particle::LandingHoney => ParticleKind::LandingHoney, | ||||||
|  |         Particle::FallingNectar => ParticleKind::FallingNectar, | ||||||
|  |         Particle::FallingSporeBlossom => ParticleKind::FallingSporeBlossom, | ||||||
|  |         Particle::Ash => ParticleKind::Ash, | ||||||
|  |         Particle::CrimsonSpore => ParticleKind::CrimsonSpore, | ||||||
|  |         Particle::WarpedSpore => ParticleKind::WarpedSpore, | ||||||
|  |         Particle::SporeBlossomAir => ParticleKind::SporeBlossomAir, | ||||||
|  |         Particle::DrippingObsidianTear => ParticleKind::DrippingObsidianTear, | ||||||
|  |         Particle::FallingObsidianTear => ParticleKind::FallingObsidianTear, | ||||||
|  |         Particle::LandingObsidianTear => ParticleKind::LandingObsidianTear, | ||||||
|  |         Particle::ReversePortal => ParticleKind::ReversePortal, | ||||||
|  |         Particle::WhiteAsh => ParticleKind::WhiteAsh, | ||||||
|  |         Particle::SmallFlame => ParticleKind::SmallFlame, | ||||||
|  |         Particle::Snowflake => ParticleKind::Snowflake, | ||||||
|  |         Particle::DrippingDripstoneLava => ParticleKind::DrippingDripstoneLava, | ||||||
|  |         Particle::FallingDripstoneLava => ParticleKind::FallingDripstoneLava, | ||||||
|  |         Particle::DrippingDripstoneWater => ParticleKind::DrippingDripstoneWater, | ||||||
|  |         Particle::FallingDripstoneWater => ParticleKind::FallingDripstoneWater, | ||||||
|  |         Particle::GlowSquidInk => ParticleKind::GlowSquidInk, | ||||||
|  |         Particle::Glow => ParticleKind::Glow, | ||||||
|  |         Particle::WaxOn => ParticleKind::WaxOn, | ||||||
|  |         Particle::WaxOff => ParticleKind::WaxOff, | ||||||
|  |         Particle::ElectricSpark => ParticleKind::ElectricSpark, | ||||||
|  |         Particle::Scrape => ParticleKind::Scrape, | ||||||
|  |         Particle::Shriek(_) => ParticleKind::Shriek, | ||||||
|  |         Particle::EggCrack => ParticleKind::EggCrack, | ||||||
|  |         Particle::DustPlume => ParticleKind::DustPlume, | ||||||
|  |         Particle::SmallGust => ParticleKind::SmallGust, | ||||||
|  |         Particle::GustEmitterLarge => ParticleKind::GustEmitterLarge, | ||||||
|  |         Particle::GustEmitterSmall => ParticleKind::GustEmitterSmall, | ||||||
|  |         Particle::Infested => ParticleKind::Infested, | ||||||
|  |         Particle::ItemCobweb => ParticleKind::ItemCobweb, | ||||||
|  |         Particle::TrialSpawnerDetection => ParticleKind::TrialSpawnerDetection, | ||||||
|  |         Particle::TrialSpawnerDetectionOminous => ParticleKind::TrialSpawnerDetectionOminous, | ||||||
|  |         Particle::VaultConnection => ParticleKind::VaultConnection, | ||||||
|  |         Particle::DustPillar => ParticleKind::DustPillar, | ||||||
|  |         Particle::OminousSpawning => ParticleKind::OminousSpawning, | ||||||
|  |         Particle::RaidOmen => ParticleKind::RaidOmen, | ||||||
|  |         Particle::TrialOmen => ParticleKind::TrialOmen, | ||||||
|  |         Particle::Trail => ParticleKind::Trail, | ||||||
|  |         Particle::BlockCrumble => ParticleKind::BlockCrumble, | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user