diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-12-27 22:02:00 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-27 22:02:00 -0600 |
| commit | 9513f42e87f64c409cdb2a100500a50e5a713bac (patch) | |
| tree | bb6aa8b6d50fddf967bcb1f759e023754ea84e49 /azalea-client/src/plugins/attack.rs | |
| parent | 588902ba4a3965982bdd84d92b20c6f7613f3978 (diff) | |
| download | azalea-drasl-9513f42e87f64c409cdb2a100500a50e5a713bac.tar.xz | |
Move Client struct to azalea crate (#297)
* move the Client struct out of azalea-client into azalea
* actually add client impls in azalea
Diffstat (limited to 'azalea-client/src/plugins/attack.rs')
| -rw-r--r-- | azalea-client/src/plugins/attack.rs | 45 |
1 files changed, 1 insertions, 44 deletions
diff --git a/azalea-client/src/plugins/attack.rs b/azalea-client/src/plugins/attack.rs index baab4333..41ce114d 100644 --- a/azalea-client/src/plugins/attack.rs +++ b/azalea-client/src/plugins/attack.rs @@ -12,7 +12,7 @@ use tracing::warn; use super::packet::game::SendGamePacketEvent; use crate::{ - Client, interact::SwingArmEvent, local_player::LocalGameMode, movement::MoveEventsSystems, + interact::SwingArmEvent, local_player::LocalGameMode, movement::MoveEventsSystems, respawn::perform_respawn, }; @@ -43,49 +43,6 @@ impl Plugin for AttackPlugin { } } -impl Client { - /// Attack an entity in the world. - /// - /// This doesn't automatically look at the entity or perform any - /// range/visibility checks, so it might trigger anticheats. - pub fn attack(&self, entity: Entity) { - self.ecs.lock().write_message(AttackEvent { - entity: self.entity, - target: entity, - }); - } - - /// Whether the player has an attack cooldown. - /// - /// Also see [`Client::attack_cooldown_remaining_ticks`]. - pub fn has_attack_cooldown(&self) -> bool { - let Some(attack_strength_scale) = self.get_component::<AttackStrengthScale>() else { - // they don't even have an AttackStrengthScale so they probably can't even - // attack? whatever, just return false - return false; - }; - *attack_strength_scale < 1.0 - } - - /// Returns the number of ticks until we can attack at full strength again. - /// - /// Also see [`Client::has_attack_cooldown`]. - pub fn attack_cooldown_remaining_ticks(&self) -> usize { - let mut ecs = self.ecs.lock(); - let Ok((attributes, ticks_since_last_attack)) = ecs - .query::<(&Attributes, &TicksSinceLastAttack)>() - .get(&ecs, self.entity) - else { - return 0; - }; - - let attack_strength_delay = get_attack_strength_delay(attributes); - let remaining_ticks = attack_strength_delay - **ticks_since_last_attack as f32; - - remaining_ticks.max(0.).ceil() as usize - } -} - /// A component that indicates that this client will be attacking the given /// entity next tick. #[derive(Clone, Component, Debug)] |
