aboutsummaryrefslogtreecommitdiff
path: root/bot/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-09-19 20:38:08 -0500
committermat <github@matdoes.dev>2022-09-19 20:38:08 -0500
commit528c1a07e3ac089ff70036a5e403eb2b8d3ae21f (patch)
treea2293b2e0aa372f9dc0e5a703047a17eb590df50 /bot/src
parent14a6f9d9f89452b56102ffc5dc61125cc2b63aff (diff)
downloadazalea-drasl-528c1a07e3ac089ff70036a5e403eb2b8d3ae21f.tar.xz
change example
Diffstat (limited to 'bot/src')
-rw-r--r--bot/src/main.rs112
1 files changed, 18 insertions, 94 deletions
diff --git a/bot/src/main.rs b/bot/src/main.rs
index f9977d99..5423e017 100644
--- a/bot/src/main.rs
+++ b/bot/src/main.rs
@@ -1,103 +1,27 @@
-#![allow(unused_variables, unused_imports)]
-use azalea_client::{Account, Event, MoveDirection};
-use azalea_core::{PositionXYZ, Vec3};
-use azalea_physics::collision::{HasCollision, MoverType};
+use azalea_client::{Account, Client, Event, MoveDirection};
+use std::convert::TryInto;
#[tokio::main]
-async fn main() -> Result<(), Box<dyn std::error::Error>> {
- println!("Hello, world!");
+async fn main() {
+ let bot = Account::offline("bot");
- // let address = "95.111.249.143:10000";
- let address = "localhost";
- // let response = azalea_client::ping::ping_server(&address.try_into().unwrap())
- // .await
- // .unwrap();
+ let (bot, mut rx) = bot.join(&"localhost".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(event) = rx.recv().await {
+ tokio::spawn(handle_event(event, bot.clone()));
+ }
+}
- 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);
- // // }
+async fn handle_event(event: Event, mut bot: Client) {
+ match event {
+ Event::Login => {
+ // tokio::time::sleep(std::time::Duration::from_secs(1)).await;
+ bot.walk(MoveDirection::Forward);
+ // loop {
+ // tokio::time::sleep(std::time::Duration::from_secs(2)).await;
// }
- 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);
- // }
- }
- _ => {}
+ // bot.walk(MoveDirection::None);
}
+ _ => {}
}
-
- println!("done");
-
- Ok(())
}