From f250978cdd789d8ceb10cb225970a408933f508b Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 5 Apr 2025 00:50:39 +0330 Subject: send attack packets at the end of the tick --- azalea-client/src/plugins/interact.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'azalea-client/src/plugins/interact.rs') diff --git a/azalea-client/src/plugins/interact.rs b/azalea-client/src/plugins/interact.rs index f9513183..f7239c17 100644 --- a/azalea-client/src/plugins/interact.rs +++ b/azalea-client/src/plugins/interact.rs @@ -23,6 +23,7 @@ use bevy_ecs::{ component::Component, entity::Entity, event::{Event, EventReader}, + observer::Trigger, query::{Changed, With}, schedule::IntoSystemConfigs, system::{Commands, Query, Res}, @@ -64,7 +65,8 @@ impl Plugin for InteractPlugin { .after(InventorySet) .after(MoveEventsSet), ), - ); + ) + .add_observer(handle_swing_arm_trigger); } } @@ -295,18 +297,21 @@ pub fn can_use_game_master_blocks( /// Swing your arm. This is purely a visual effect and won't interact with /// anything in the world. -#[derive(Event)] +#[derive(Event, Clone, Debug)] pub struct SwingArmEvent { pub entity: Entity, } +pub fn handle_swing_arm_trigger(trigger: Trigger, mut commands: Commands) { + commands.trigger(SendPacketEvent::new( + trigger.event().entity, + ServerboundSwing { + hand: InteractionHand::MainHand, + }, + )); +} pub fn handle_swing_arm_event(mut events: EventReader, mut commands: Commands) { for event in events.read() { - commands.trigger(SendPacketEvent::new( - event.entity, - ServerboundSwing { - hand: InteractionHand::MainHand, - }, - )); + commands.trigger(event.clone()); } } -- cgit v1.2.3