aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/todo/mine_a_chunk.rs
blob: 8ba33f5ce6c2ecaf2ec04b2265ce6780e0ab92cd (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
52
53
use azalea::{prelude::*, swarm::prelude::*};

#[tokio::main]
async fn main() -> AppExit {
    let mut accounts = Vec::new();
    let mut states = Vec::new();

    for i in 0..10 {
        accounts.push(Account::offline(&format!("bot{i}")));
        states.push(State::default());
    }

    SwarmBuilder::new()
        .add_accounts(accounts.clone())
        .set_handler(handle)
        .set_swarm_handler(swarm_handle)
        .start("localhost")
        .await
}

#[derive(Clone, Component, Default)]
struct State {}

#[derive(Clone, Default, Resource)]
struct SwarmState {}

async fn handle(bot: Client, event: Event, state: State) -> eyre::Result<()> {
    Ok(())
}

async fn swarm_handle(swarm: Swarm, event: SwarmEvent, state: SwarmState) -> eyre::Result<()> {
    match &event {
        SwarmEvent::Login => {
            swarm.goto(azalea::BlockPos::new(0, 70, 0)).await;
            // or bots.goto_goal(pathfinder::Goals::Goto(azalea::BlockPos(0, 70, 0))).await;

            // destroy the blocks in this area and then leave

            swarm
                .fill(
                    azalea::Selection::Range(
                        azalea::BlockPos::new(0, 0, 0),
                        azalea::BlockPos::new(16, 255, 16),
                    ),
                    azalea::block::Air,
                )
                .await;
        }
        _ => {}
    }

    Ok(())
}