From 45b21ea54bc21d87ea0650afadcc474ddccf5249 Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Wed, 27 Mar 2024 22:26:40 +0100 Subject: Fix: Pest Tracker Waypoint trigerring with some other particles (#1284) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/garden/pests/PestParticleWaypoint.kt | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'src/main/java/at') 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 96a14c059..ed444e52e 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 @@ -8,10 +8,10 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.PacketEvent 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.features.garden.GardenPlotAPI import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled -import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer +import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayerIgnoreY import at.hannibal2.skyhanni.utils.LocationUtils.playerLocation import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzVec @@ -40,25 +40,26 @@ class PestParticleWaypoint { private var locations = mutableListOf() private var particles = 0 private var lastParticles = 0 + private var isPointingToPest = false @SubscribeEvent fun onItemClick(event: ItemClickEvent) { if (!isEnabled()) return if (PestAPI.hasVacuumInHand()) { if (event.clickType == ClickType.LEFT_CLICK && !Minecraft.getMinecraft().thePlayer.isSneaking) { - lastPestTrackerUse = SimpleTimeMark.now() reset() + lastPestTrackerUse = SimpleTimeMark.now() } } } @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { - lastPestTrackerUse = SimpleTimeMark.farPast() reset() } private fun reset() { + lastPestTrackerUse = SimpleTimeMark.farPast() locations.clear() guessPoint = null lastParticlePoint = null @@ -66,13 +67,25 @@ class PestParticleWaypoint { secondParticlePoint = null particles = 0 lastParticles = 0 + isPointingToPest = false } @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) fun onReceiveParticle(event: ReceiveParticleEvent) { if (!isEnabled()) return - if (event.type != EnumParticleTypes.REDSTONE) return + if (event.type != EnumParticleTypes.REDSTONE || event.speed != 1f) return + + val darkYellow = LorenzVec(0.0, 0.8, 0.0) + val yellow = LorenzVec(0.8, 0.8, 0.0) + val redPest = LorenzVec(0.8, 0.4, 0.0) + val redPlot = LorenzVec(0.8, 0.0, 0.0) + isPointingToPest = when (event.offset.round(5)) { + redPlot -> false + redPest, yellow, darkYellow -> true + else -> return + } val location = event.location + if (config.hideParticles) event.cancel() if (lastPestTrackerUse.passedSince() > 3.seconds) return @@ -112,11 +125,9 @@ class PestParticleWaypoint { } val waypoint = getWaypoint() ?: return - val distance = GardenPlotAPI.closestCenterPlot(waypoint)?.distanceIgnoreY(waypoint) ?: return - val isCloseToPlotCenter = distance < 4 - val text = if (isCloseToPlotCenter) "§cInfected Plot Guess" else "§aPest Guess" - val color = if (isCloseToPlotCenter) LorenzColor.RED else LorenzColor.GREEN + val text = if (isPointingToPest) "§aPest Guess" else "§cInfected Plot Guess" + val color = if (isPointingToPest) LorenzColor.GREEN else LorenzColor.RED event.drawWaypointFilled(waypoint, color.toColor(), beacon = true) event.drawDynamicText(waypoint, text, 1.3) @@ -139,14 +150,18 @@ class PestParticleWaypoint { @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return - if (lastPestTrackerUse.passedSince() !in 1.seconds..config.showForSeconds.seconds) return val guessPoint = guessPoint ?: return - if (guessPoint.distanceToPlayer() > 8.0) return - lastPestTrackerUse = SimpleTimeMark.farPast() + if (guessPoint.distanceToPlayerIgnoreY() > 8) return + if (isPointingToPest && lastPestTrackerUse.passedSince() !in 1.seconds..config.showForSeconds.seconds) return reset() } + @SubscribeEvent + fun onPestUpdate(event: PestUpdateEvent) { + if (PestAPI.scoreboardPests == 0) reset() + } + private fun calculateWaypoint(list: MutableList): LorenzVec? { val firstParticle = firstParticlePoint ?: return null -- cgit