aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/testbot/killaura.rs
blob: 4f29a0f2855d14842a1fb777e06f76a1d24aa8af (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
use azalea::{
    ecs::prelude::*,
    entity::{Dead, LocalEntity, Position, metadata::AbstractMonster},
    prelude::*,
};

use crate::State;

pub fn tick(bot: Client, state: State) -> anyhow::Result<()> {
    if !state.killaura {
        return Ok(());
    }
    if bot.has_attack_cooldown() {
        return Ok(());
    }
    let bot_position = bot.eye_position();

    let nearest_entity = bot.nearest_entity_by::<&Position, (
        With<AbstractMonster>,
        Without<LocalEntity>,
        Without<Dead>,
    )>(|position: &Position| {
        let distance = bot_position.distance_to(**position);
        distance < 4.
    });

    if let Some(nearest_entity) = nearest_entity {
        println!("attacking {nearest_entity:?}");
        nearest_entity.attack();
    }

    Ok(())
}