blob: 16721c1cee4fdbc9572458e90680a969e257a262 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
use azalea_client::attack::{
AttackEvent, AttackStrengthScale, TicksSinceLastAttack, get_attack_strength_delay,
};
use azalea_entity::Attributes;
use bevy_ecs::entity::Entity;
use crate::Client;
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.write().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 ecs = self.ecs.read();
let Some(attributes) = ecs.get::<Attributes>(self.entity) else {
return 0;
};
let Some(ticks_since_last_attack) = ecs.get::<TicksSinceLastAttack>(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
}
}
|