diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt index d4a63689b..45fc2f50d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.events.ReceiveParticleEvent import at.hannibal2.skyhanni.events.garden.pests.PestUpdateEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayerIgnoreY import at.hannibal2.skyhanni.utils.LocationUtils.playerLocation import at.hannibal2.skyhanni.utils.LorenzVec @@ -37,7 +38,7 @@ class PestParticleWaypoint { private var secondParticlePoint: LorenzVec? = null private var lastParticlePoint: LorenzVec? = null private var guessPoint: LorenzVec? = null - private val locations = mutableListOf<LorenzVec>() + private var locations = listOf<LorenzVec>() private var particles = 0 private var lastParticles = 0 private var isPointingToPest = false @@ -61,7 +62,7 @@ class PestParticleWaypoint { private fun reset() { lastPestTrackerUse = SimpleTimeMark.farPast() - locations.clear() + locations = emptyList() guessPoint = null lastParticlePoint = null firstParticlePoint = null @@ -100,13 +101,17 @@ class PestParticleWaypoint { } else if (secondParticlePoint == null) { secondParticlePoint = location lastParticlePoint = location - locations.add(location) + locations = locations.editCopy { + add(location) + } } else { val firstDistance = secondParticlePoint?.let { firstParticlePoint?.distance(it) } ?: return val distance = lastParticlePoint?.distance(location) ?: return if ((distance - firstDistance).absoluteValue > 0.1) return lastParticlePoint = location - locations.add(location) + locations = locations.editCopy { + add(location) + } } ++particles } @@ -168,7 +173,7 @@ class PestParticleWaypoint { private fun calculateWaypoint(): LorenzVec? { val firstParticle = firstParticlePoint ?: return null - val list = locations.toMutableSet() + val list = locations.toList() var pos = LorenzVec(0.0, 0.0, 0.0) for ((i, particle) in list.withIndex()) { pos = pos.add(particle.subtract(firstParticle).divide(i.toDouble() + 1.0)) |