Skip to content

Commit

Permalink
Refactor JumpablePathfinderStrategy for height calculation
Browse files Browse the repository at this point in the history
The "JumpablePathfinderStrategy" class has been revised to include downward jumps in its calculations. A new private method "isJumpingDown" is introduced, which is used to calculate the height difference whether the entity is jumping upwards or downwards. Consequently, this increases the accuracy of the entity jumping mechanism in the game.
  • Loading branch information
GodCipher committed Mar 1, 2024
1 parent f95396d commit c78c05f
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,21 @@ public boolean isValid(@NonNull PathValidationContext pathValidationContext) {
return true;
}

if ((position.getBlockY() - lastValidPosition.getBlockY()) > jumpHeight) return false;
int heightDiff = position.getBlockY() - lastValidPosition.getBlockY();
if (isJumpingDown(position, lastValidPosition)) {
heightDiff *= -1;
}

if (heightDiff > jumpHeight) {
return false;
}

return startBlock.isPassable() && position.distance(lastValidPosition) <= maxJumpDistance;
}

private boolean isJumpingDown(PathPosition position, PathPosition lastValidPosition) {
return position.getBlockX() == lastValidPosition.getBlockX()
&& position.getBlockZ() == lastValidPosition.getBlockZ()
&& position.getBlockY() < lastValidPosition.getBlockY();
}
}

0 comments on commit c78c05f

Please sign in to comment.