mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
make lookat actually work probably
This commit is contained in:
parent
9b67d7dafb
commit
6daaf9e6b7
3 changed files with 21 additions and 5 deletions
|
@ -93,10 +93,12 @@ fn tick_execute_path(bot: &mut Client, path: &mut VecDeque<Node>) {
|
|||
return;
|
||||
};
|
||||
let center = target.pos.center();
|
||||
println!("going to {center:?} (at {pos:?})", pos = bot.entity().pos());
|
||||
bot.look_at(¢er);
|
||||
bot.walk(WalkDirection::Forward);
|
||||
|
||||
if target.is_reached(&bot.entity()) {
|
||||
println!("ok target reached");
|
||||
path.pop_front();
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +120,12 @@ impl Node {
|
|||
/// Returns whether the entity is at the node and should start going to the
|
||||
/// next node.
|
||||
pub fn is_reached(&self, entity: &EntityData) -> bool {
|
||||
println!(
|
||||
"entity.yya: {} {:?}=={:?}",
|
||||
entity.yya,
|
||||
BlockPos::from(entity.pos()),
|
||||
self.pos
|
||||
);
|
||||
entity.yya == 0. && BlockPos::from(entity.pos()) == self.pos
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{Client, Event};
|
|||
use async_trait::async_trait;
|
||||
use azalea_core::Vec3;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::{f64::consts::PI, sync::Arc};
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Plugin {
|
||||
|
@ -38,9 +38,10 @@ impl BotTrait for azalea_client::Client {
|
|||
fn look_at(&mut self, pos: &Vec3) {
|
||||
// borrowed from mineflayer's Bot.lookAt because i didn't want to do math
|
||||
let delta = self.entity().pos() - pos;
|
||||
let x_rot = f64::atan2(-delta.x, -delta.z);
|
||||
let x_rot = (PI - f64::atan2(-delta.x, -delta.z)) * (180.0 / PI);
|
||||
let ground_distance = f64::sqrt(delta.x * delta.x + delta.z * delta.z);
|
||||
let y_rot = f64::atan2(delta.y, ground_distance);
|
||||
let y_rot = f64::atan2(delta.y, ground_distance) * -(180.0 / PI);
|
||||
println!("x_rot: {}, y_rot: {}", x_rot, y_rot);
|
||||
self.set_rotation(y_rot as f32, x_rot as f32);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,14 +32,21 @@ async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()>
|
|||
Event::Chat(m) => {
|
||||
println!("{}", m.message().to_ansi(None));
|
||||
if m.message().to_string() == "<py5> goto" {
|
||||
bot.goto(BlockPosGoal::from(BlockPos::new(0, -60, 12)));
|
||||
let target_pos: BlockPos = bot
|
||||
.dimension
|
||||
.read()
|
||||
.entity_by_uuid(&uuid::uuid!("6536bfed869548fd83a1ecd24cf2a0fd"))
|
||||
.unwrap()
|
||||
.pos()
|
||||
.into();
|
||||
bot.goto(BlockPosGoal::from(target_pos));
|
||||
}
|
||||
}
|
||||
Event::Initialize => {
|
||||
println!("initialized");
|
||||
}
|
||||
Event::Tick => {
|
||||
bot.jump();
|
||||
// bot.jump();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue