diff options
| author | mat <git@matdoes.dev> | 2025-12-16 09:42:54 -0200 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-12-16 09:42:54 -0200 |
| commit | 6f2fe2c9e5af1f2fa2c1b99c3d4ea0a7e90ae16c (patch) | |
| tree | b01afabf10b51e3024dfdc139803b590a36b08c2 /azalea-client/src/plugins | |
| parent | 9bd529277f5025805da95f081657c180972e487e (diff) | |
| download | azalea-drasl-6f2fe2c9e5af1f2fa2c1b99c3d4ea0a7e90ae16c.tar.xz | |
change KnockbackEvent to an EntityEvent and fix ClientboundExplode representation
ty mahtog for pointing out the latter issue <3
Diffstat (limited to 'azalea-client/src/plugins')
| -rw-r--r-- | azalea-client/src/plugins/movement.rs | 31 | ||||
| -rw-r--r-- | azalea-client/src/plugins/packet/game/mod.rs | 17 |
2 files changed, 23 insertions, 25 deletions
diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs index fd85de2d..c4409722 100644 --- a/azalea-client/src/plugins/movement.rs +++ b/azalea-client/src/plugins/movement.rs @@ -46,10 +46,9 @@ impl Plugin for MovementPlugin { fn build(&self, app: &mut App) { app.add_message::<StartWalkEvent>() .add_message::<StartSprintEvent>() - .add_message::<KnockbackEvent>() .add_systems( Update, - (handle_sprint, handle_walk, handle_knockback) + (handle_sprint, handle_walk) .chain() .in_set(MoveEventsSystems) .after(update_bounding_box) @@ -70,7 +69,8 @@ impl Plugin for MovementPlugin { send_position.after(PhysicsSystems), ) .chain(), - ); + ) + .add_observer(handle_knockback); } } @@ -655,27 +655,26 @@ fn has_enough_impulse_to_start_sprinting(physics_state: &PhysicsState) -> bool { /// Usually `KnockbackKind::Set` is used for normal knockback and /// `KnockbackKind::Add` is used for explosions, but some servers (notably /// Hypixel) use explosions for knockback. -#[derive(Message)] +#[derive(EntityEvent, Debug, Clone)] pub struct KnockbackEvent { pub entity: Entity, - pub knockback: KnockbackType, + pub data: KnockbackData, } -pub enum KnockbackType { +#[derive(Debug, Clone)] +pub enum KnockbackData { Set(Vec3), Add(Vec3), } -pub fn handle_knockback(mut query: Query<&mut Physics>, mut events: MessageReader<KnockbackEvent>) { - for event in events.read() { - if let Ok(mut physics) = query.get_mut(event.entity) { - match event.knockback { - KnockbackType::Set(velocity) => { - physics.velocity = velocity; - } - KnockbackType::Add(velocity) => { - physics.velocity += velocity; - } +pub fn handle_knockback(knockback: On<KnockbackEvent>, mut query: Query<&mut Physics>) { + if let Ok(mut physics) = query.get_mut(knockback.entity) { + match knockback.data { + KnockbackData::Set(velocity) => { + physics.velocity = velocity; + } + KnockbackData::Add(velocity) => { + physics.velocity += velocity; } } } diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs index f39a9f8f..edb755c9 100644 --- a/azalea-client/src/plugins/packet/game/mod.rs +++ b/azalea-client/src/plugins/packet/game/mod.rs @@ -34,7 +34,7 @@ use crate::{ interact::BlockStatePredictionHandler, inventory::{ClientsideCloseContainerEvent, MenuOpenedEvent, SetContainerContentEvent}, local_player::{Hunger, InstanceHolder, LocalGameMode, TabList}, - movement::{KnockbackEvent, KnockbackType}, + movement::{KnockbackData, KnockbackEvent}, packet::{as_system, declare_packet_handlers}, player::{GameProfileComponent, PlayerInfo}, tick_counter::TicksConnected, @@ -738,14 +738,13 @@ impl GamePacketHandler<'_> { // this is to make sure the same entity velocity update doesn't get sent // multiple times when in swarms - let knockback = KnockbackType::Set(p.delta.to_vec3()); + let data = KnockbackData::Set(p.delta.to_vec3()); commands.entity(entity).queue(RelativeEntityUpdate::new( instance_holder.partial_instance.clone(), move |entity_mut| { - entity_mut.world_scope(|world| { - world.write_message(KnockbackEvent { entity, knockback }) - }); + entity_mut + .world_scope(|world| world.trigger(KnockbackEvent { entity, data })); }, )); }, @@ -1262,13 +1261,13 @@ impl GamePacketHandler<'_> { pub fn delete_chat(&mut self, _p: &ClientboundDeleteChat) {} pub fn explode(&mut self, p: &ClientboundExplode) { - trace!("Got explode packet {p:?}"); + println!("Got explode packet {p:?}"); - as_system::<MessageWriter<_>>(self.ecs, |mut knockback_events| { + as_system::<Commands>(self.ecs, |mut knockback_events| { if let Some(knockback) = p.player_knockback { - knockback_events.write(KnockbackEvent { + knockback_events.trigger(KnockbackEvent { entity: self.player, - knockback: KnockbackType::Set(knockback), + data: KnockbackData::Set(knockback), }); } }); |
