aboutsummaryrefslogtreecommitdiff
path: root/bot/src/main.rs
blob: f9977d99fa0ece7c1ad9b0e869c2af9bcc8a17c1 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#![allow(unused_variables, unused_imports)]
use azalea_client::{Account, Event, MoveDirection};
use azalea_core::{PositionXYZ, Vec3};
use azalea_physics::collision::{HasCollision, MoverType};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("Hello, world!");

    // let address = "95.111.249.143:10000";
    let address = "localhost";
    // let response = azalea_client::ping::ping_server(&address.try_into().unwrap())
    //     .await
    //     .unwrap();

    // println!("{}", response.description.to_ansi(None));
    let account = Account::offline("bot");
    let (mut client, mut rx) = account.join(&address.try_into().unwrap()).await.unwrap();
    println!("connected");

    while let Some(e) = &rx.recv().await {
        match e {
            // TODO: have a "loaded" or "ready" event that fires when all chunks are loaded
            Event::Login => {}
            // Event::GameTick => {
            //     let world = client.world();
            //     if let Some(b) = world.find_one_entity(|e| {
            //         e.uuid == uuid::uuid!("6536bfed-8695-48fd-83a1-ecd24cf2a0fd")
            //     }) {
            //         // let world = state.world.as_ref().unwrap();
            //         // world.
            //         println!("{:?}", b);
            //     }
            //     // world.get_block_state(state.player.entity.pos);
            //     // println!("{}", p.message.to_ansi(None));
            //     // if p.message.to_ansi(None) == "<py5> ok" {
            //     //     let state = client.state.lock();
            //     //     let world = state.world.as_ref().unwrap();
            //     //     let c = world.get_block_state(&BlockPos::new(5, 78, -2)).unwrap();
            //     //     println!("block state: {:?}", c);
            //     // }
            // }
            Event::Chat(m) => {
                let message = m.message().to_string();
                println!("{}", message);

                match &message[..] {
                    "stop" => {
                        println!("stopping");
                        client.walk(MoveDirection::None);
                    }
                    "forward" => {
                        println!("moving forward");
                        client.walk(MoveDirection::Forward);
                    }
                    "backward" => {
                        println!("moving backward");
                        client.walk(MoveDirection::Backward);
                    }
                    "left" => {
                        println!("moving left");
                        client.walk(MoveDirection::Left);
                    }
                    "right" => {
                        println!("moving right");
                        client.walk(MoveDirection::Right);
                    }
                    _ => {}
                }

                //     let new_pos = {
                //         let dimension_lock = client.dimension.lock().unwrap();
                //         let player = client.player.lock().unwrap();
                //         let entity = player
                //             .entity(&dimension_lock)
                //             .expect("Player entity is not in world");
                //         entity.pos().add_y(-0.5)
                //     };

                // println!("{:?}", new_pos);
                // client.set_pos(new_pos).await.unwrap();
                // client.move_entity()

                // println!("{}", m.to_ansi(None));
                // if let Err(e) = client
                //     .move_entity(&Vec3 {
                //         x: 0.,
                //         y: -0.5,
                //         z: 0.,
                //     })
                //     .await
                // {
                //     eprintln!("{:?}", e);
                // }
            }
            _ => {}
        }
    }

    println!("done");

    Ok(())
}