aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/bot.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-12-15 11:26:40 -0600
committerGitHub <noreply@github.com>2023-12-15 11:26:40 -0600
commita707e2eb82b74994a16083b31fa4576332cf1995 (patch)
treedb6c2ac94dd73590befd68a9b1b0ef960410b0df /azalea/src/bot.rs
parent59e140ddd655c7dc6e35109b91286118c51bcc06 (diff)
downloadazalea-drasl-a707e2eb82b74994a16083b31fa4576332cf1995.tar.xz
Add mining to the pathfinder (#122)
* basic pathfinder mining poc * mining descending and autotool * pathfinder mining descending * pathfinder fixes * allow disabling pathfinder miner and other fixes * small optimization to avoid chunk vec iter lookup sometimes * seeded rng in pathfinder bench * consistently use f32::INFINITY this brings performance much closer to how it was before * astar heuristic optimization from baritone * add downward_move * fix downward move execute * avoid liquids and falling blocks when mining * fix COST_HEURISTIC * fix to not path through flowing liquids * only reset pathfinder timeout while mining if the block is close enough * cache mining costs of block positions * fix mine_while_at_start and move PathfinderDebugParticles to its own module * add ReachBlockPosGoal in other news: azalea's sin/cos functions were broken this whole time and i never noticed * clippy and add things that i accidentally didn't commit * improve wording on doc for azalea::pathfinder
Diffstat (limited to 'azalea/src/bot.rs')
-rw-r--r--azalea/src/bot.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs
index ccc016e6..529bb251 100644
--- a/azalea/src/bot.rs
+++ b/azalea/src/bot.rs
@@ -170,27 +170,35 @@ fn look_at_listener(
) {
for event in events.read() {
if let Ok((position, eye_height, mut look_direction)) = query.get_mut(event.entity) {
- let (y_rot, x_rot) =
+ let new_look_direction =
direction_looking_at(&position.up(eye_height.into()), &event.position);
trace!(
"look at {:?} (currently at {:?})",
event.position,
**position
);
- (look_direction.y_rot, look_direction.x_rot) = (y_rot, x_rot);
+ *look_direction = new_look_direction;
}
}
}
-/// Return the (`y_rot`, `x_rot`) that would make a client at `current` be
+/// Return the look direction that would make a client at `current` be
/// looking at `target`.
-fn direction_looking_at(current: &Vec3, target: &Vec3) -> (f32, f32) {
+pub fn direction_looking_at(current: &Vec3, target: &Vec3) -> LookDirection {
// borrowed from mineflayer's Bot.lookAt because i didn't want to do math
let delta = target - current;
let y_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 x_rot = f64::atan2(delta.y, ground_distance) * -(180.0 / PI);
- (y_rot as f32, x_rot as f32)
+
+ // clamp
+ let y_rot = y_rot.rem_euclid(360.0);
+ let x_rot = x_rot.clamp(-90.0, 90.0) % 360.0;
+
+ LookDirection {
+ x_rot: x_rot as f32,
+ y_rot: y_rot as f32,
+ }
}
/// A [`PluginGroup`] for the plugins that add extra bot functionality to the