aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-10-01 14:43:51 -0500
committermat <git@matdoes.dev>2023-10-01 14:43:51 -0500
commita440c23a3b0f348fc89e504b4ef0ccb1dc3ec93a (patch)
treed2f46bfd4013d1626e5bb0028332fea512d3de4b
parentaee48061cf7ba0db6f3d0bd87b044aeac9490f25 (diff)
downloadazalea-drasl-a440c23a3b0f348fc89e504b4ef0ccb1dc3ec93a.tar.xz
more reliable pathfinder parkour
-rw-r--r--azalea/src/pathfinder/moves/mod.rs5
-rw-r--r--azalea/src/pathfinder/moves/parkour.rs30
2 files changed, 27 insertions, 8 deletions
diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs
index 61dc8b68..f3ed7dff 100644
--- a/azalea/src/pathfinder/moves/mod.rs
+++ b/azalea/src/pathfinder/moves/mod.rs
@@ -127,10 +127,7 @@ pub fn default_move(world: &Instance, node: BlockPos) -> Vec<Edge> {
#[must_use]
pub fn default_is_reached(
IsReachedCtx {
- position,
- target,
- // physics,
- ..
+ position, target, ..
}: IsReachedCtx,
) -> bool {
BlockPos::from(position) == target
diff --git a/azalea/src/pathfinder/moves/parkour.rs b/azalea/src/pathfinder/moves/parkour.rs
index b6a839e6..5f81149b 100644
--- a/azalea/src/pathfinder/moves/parkour.rs
+++ b/azalea/src/pathfinder/moves/parkour.rs
@@ -9,7 +9,7 @@ use crate::{
use super::{
default_is_reached, is_block_passable, is_block_solid, is_passable, is_standable, Edge,
- ExecuteCtx, MoveData,
+ ExecuteCtx, IsReachedCtx, MoveData,
};
pub fn parkour_move(world: &Instance, node: BlockPos) -> Vec<Edge> {
@@ -51,7 +51,7 @@ fn parkour_forward_1_move(world: &Instance, pos: BlockPos) -> Vec<Edge> {
target: pos + offset,
data: MoveData {
execute: &execute_parkour_move,
- is_reached: &default_is_reached,
+ is_reached: &parkour_is_reached,
},
},
cost,
@@ -156,6 +156,7 @@ fn parkour_headhitter_forward_1_move(world: &Instance, pos: BlockPos) -> Vec<Edg
fn execute_parkour_move(
ExecuteCtx {
entity,
+ position,
target,
start,
look_at_events,
@@ -173,7 +174,7 @@ fn execute_parkour_move(
let jump_distance = i32::max((target - start).x.abs(), (target - start).z.abs());
- if jump_distance > 2 {
+ if jump_distance >= 4 {
sprint_events.send(StartSprintEvent {
entity,
direction: SprintDirection::Forward,
@@ -185,7 +186,18 @@ fn execute_parkour_move(
});
}
- jump_events.send(JumpEvent { entity });
+ let x_dir = (target.x - start.x).clamp(-1, 1);
+ let z_dir = (target.z - start.z).clamp(-1, 1);
+ let dir = BlockPos::new(x_dir, 0, z_dir);
+ let jump_at_pos = start + dir;
+
+ let is_at_start_block = BlockPos::from(position) == start;
+ let is_at_jump_block = BlockPos::from(position) == jump_at_pos;
+ let is_in_air = position.y - start.y as f64 > 0.0001;
+
+ if !is_at_start_block && (is_at_jump_block || is_in_air) {
+ jump_events.send(JumpEvent { entity });
+ }
}
fn execute_headhitter_parkour_move(
@@ -231,3 +243,13 @@ fn execute_headhitter_parkour_move(
jump_events.send(JumpEvent { entity });
}
}
+
+#[must_use]
+pub fn parkour_is_reached(
+ IsReachedCtx {
+ position, target, ..
+ }: IsReachedCtx,
+) -> bool {
+ // 0.094 and not 0 for lilypads
+ BlockPos::from(position) == target && (position.y - target.y as f64) < 0.094
+}