Skip to content

Commit

Permalink
fixed errors when path is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed Oct 2, 2024
1 parent cc3ea04 commit f8fd5fb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ object IslandGraphs {

private fun onCurrentPath(): Boolean {
val path = fastestPath ?: return false
if (path.isEmpty()) return false
val closest = path.nodes.minBy { it.position.distanceSqToPlayer() }
val distance = closest.position.distanceToPlayer()
if (distance > 7) return false
Expand Down Expand Up @@ -441,12 +442,14 @@ object IslandGraphs {
if (label == "") return
val path = fastestPath ?: return
var distance = 0.0
for ((a, b) in path.zipWithNext()) {
distance += a.position.distance(b.position)
if (path.isNotEmpty()) {
for ((a, b) in path.zipWithNext()) {
distance += a.position.distance(b.position)
}
val distanceToPlayer = path.first().position.distanceToPlayer()
distance += distanceToPlayer
distance = distance.roundTo(1)
}
val distanceToPlayer = path.first().position.distanceToPlayer()
distance += distanceToPlayer
distance = distance.roundTo(1)

if (distance == lastDistance) return
lastDistance = distance
Expand Down

0 comments on commit f8fd5fb

Please sign in to comment.