aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-09-30 15:51:24 -0500
committermat <git@matdoes.dev>2023-09-30 15:51:24 -0500
commit2c8e1e7e85074051b77264d6c5a6b434e0ffe68e (patch)
treed40fda138ae41e6c882ee093316b400e2da4fff1
parentaf5134a0f9b980df00cc9c4b34f3c8964ee62fd7 (diff)
downloadazalea-drasl-2c8e1e7e85074051b77264d6c5a6b434e0ffe68e.tar.xz
improve descending in pathfinder more
-rw-r--r--azalea/src/pathfinder/moves/basic.rs46
1 files changed, 32 insertions, 14 deletions
diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs
index 5d8f1c54..4219f1e7 100644
--- a/azalea/src/pathfinder/moves/basic.rs
+++ b/azalea/src/pathfinder/moves/basic.rs
@@ -164,22 +164,36 @@ fn execute_descend_move(
) {
let center = target.center();
let horizontal_distance_from_target = (center - position).horizontal_distance_sqr().sqrt();
+ let horizontal_distance_from_start =
+ (start.center() - position).horizontal_distance_sqr().sqrt();
- let dest_ahead = (start + (target - start) * 2).center();
-
- println!();
- println!("center: {center:?}, dest_ahead: {dest_ahead:?}");
- println!("position: {position:?}");
+ let dest_ahead = BlockPos::new(
+ start.x + (target.x - start.x) * 2,
+ target.y,
+ start.z + (target.z - start.z) * 2,
+ );
if BlockPos::from(position) != target || horizontal_distance_from_target > 0.25 {
- look_at_events.send(LookAtEvent {
- entity,
- position: dest_ahead,
- });
- sprint_events.send(StartSprintEvent {
- entity,
- direction: SprintDirection::Forward,
- });
+ // if we're only falling one block then it's fine to try to overshoot
+ if horizontal_distance_from_start < 1.25 || start.y - target.y == 1 {
+ look_at_events.send(LookAtEvent {
+ entity,
+ position: dest_ahead.center(),
+ });
+ sprint_events.send(StartSprintEvent {
+ entity,
+ direction: SprintDirection::Forward,
+ });
+ } else {
+ look_at_events.send(LookAtEvent {
+ entity,
+ position: center,
+ });
+ sprint_events.send(StartSprintEvent {
+ entity,
+ direction: SprintDirection::Forward,
+ });
+ }
}
}
#[must_use]
@@ -191,7 +205,11 @@ pub fn is_reached_descend_move(
..
}: IsReachedCtx,
) -> bool {
- let dest_ahead = start + (target - start) * 2;
+ let dest_ahead = BlockPos::new(
+ start.x + (target.x - start.x) * 2,
+ target.y,
+ start.z + (target.z - start.z) * 2,
+ );
(BlockPos::from(position) == target || BlockPos::from(position) == dest_ahead)
&& (position.y - target.y as f64) < 0.5