aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-16 17:12:56 -0630
committermat <git@matdoes.dev>2025-06-17 09:14:37 +0930
commit319d144995e0ca635806941cbb5d6ceaf0fcf515 (patch)
treef7f8f3370d99db1bd01d65dddd7d0522557bcb3f /azalea-client/src/plugins
parentf82cf7fa859f2bab8207662e74f49bad4999f8fd (diff)
downloadazalea-drasl-319d144995e0ca635806941cbb5d6ceaf0fcf515.tar.xz
take Entity instead of MinecraftEntityId in Client::attack
Diffstat (limited to 'azalea-client/src/plugins')
-rw-r--r--azalea-client/src/plugins/attack.rs40
1 files changed, 26 insertions, 14 deletions
diff --git a/azalea-client/src/plugins/attack.rs b/azalea-client/src/plugins/attack.rs
index 2409dacc..86ed5de5 100644
--- a/azalea-client/src/plugins/attack.rs
+++ b/azalea-client/src/plugins/attack.rs
@@ -1,15 +1,16 @@
use azalea_core::{game_type::GameMode, tick::GameTick};
use azalea_entity::{
Attributes, Physics,
+ indexing::EntityIdIndex,
metadata::{ShiftKeyDown, Sprinting},
update_bounding_box,
};
use azalea_physics::PhysicsSet;
use azalea_protocol::packets::game::s_interact::{self, ServerboundInteract};
-use azalea_world::MinecraftEntityId;
use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
+use tracing::warn;
use super::packet::game::SendPacketEvent;
use crate::{
@@ -45,10 +46,10 @@ impl Plugin for AttackPlugin {
impl Client {
/// Attack the entity with the given id.
- pub fn attack(&self, entity_id: MinecraftEntityId) {
+ pub fn attack(&self, entity: Entity) {
self.ecs.lock().send_event(AttackEvent {
entity: self.entity,
- target: entity_id,
+ target: entity,
});
}
@@ -87,41 +88,51 @@ impl Client {
/// entity next tick.
#[derive(Component, Clone, Debug)]
pub struct AttackQueued {
- pub target: MinecraftEntityId,
+ pub target: Entity,
}
pub fn handle_attack_queued(
mut commands: Commands,
mut query: Query<(
Entity,
- &AttackQueued,
- &LocalGameMode,
&mut TicksSinceLastAttack,
&mut Physics,
&mut Sprinting,
+ &AttackQueued,
+ &LocalGameMode,
&ShiftKeyDown,
+ &EntityIdIndex,
)>,
) {
for (
- entity,
- attack_queued,
- game_mode,
+ client_entity,
mut ticks_since_last_attack,
mut physics,
mut sprinting,
+ attack_queued,
+ game_mode,
sneaking,
+ entity_id_index,
) in &mut query
{
- commands.entity(entity).remove::<AttackQueued>();
+ let target_entity = attack_queued.target;
+ let Some(target_entity_id) = entity_id_index.get_by_ecs_entity(target_entity) else {
+ warn!("tried to attack entity {target_entity} which isn't in our EntityIdIndex");
+ continue;
+ };
+
+ commands.entity(client_entity).remove::<AttackQueued>();
commands.trigger(SendPacketEvent::new(
- entity,
+ client_entity,
ServerboundInteract {
- entity_id: attack_queued.target,
+ entity_id: target_entity_id,
action: s_interact::ActionType::Attack,
using_secondary_action: **sneaking,
},
));
- commands.trigger(SwingArmEvent { entity });
+ commands.trigger(SwingArmEvent {
+ entity: client_entity,
+ });
// we can't attack if we're in spectator mode but it still sends the attack
// packet
@@ -142,7 +153,8 @@ pub fn handle_attack_queued(
pub struct AttackEvent {
/// Our client entity that will send the packets to attack.
pub entity: Entity,
- pub target: MinecraftEntityId,
+ /// The entity that will be attacked.
+ pub target: Entity,
}
pub fn handle_attack_event(mut events: EventReader<AttackEvent>, mut commands: Commands) {
for event in events.read() {