aboutsummaryrefslogtreecommitdiff
path: root/examples/pvp.rs
blob: 5febdd4528ace1a3d6bfbd5ffa41505c2f74d75d (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::{Account, Accounts, Event, pathfinder};

#[tokio::main]
async fn main() {
    let accounts = Accounts::new();
    for i in 0..10 {
        accounts.add(Account::offline(format!("bot{}", i)));
    }

    let bots = accounts.join("localhost".try_into().unwrap()).await.unwrap();

    match bots.next().await {
        Event::Tick {
            // choose an arbitrary player within render distance to target
            if let Some(target) = bots.world.find_one_entity(|e| e.id == "minecraft:player") {
                for bot in bots {
                    bot.tick_goto_goal(
                        pathfinder::Goals::Reach(target.bounding_box)
                    );
                    // if target.bounding_box.distance(bot.eyes) < bot.reach_distance() {
                    if bot.entity.can_reach(target.bounding_box) {
                        bot.swing();
                    }
                    if !h.using_held_item() && bot.state.lock().hunger <= 17 {
                        bot.hold(azalea::ItemGroup::Food);
                        tokio::task::spawn(bot.use_held_item());
                    }
                }
            }
        },
        _ => {}
    }
}