From 6e32cd257e2ff2274881df3d6db50d0e851dff0c Mon Sep 17 00:00:00 2001 From: Alexia Luna Date: Sun, 17 Mar 2024 19:10:41 +0100 Subject: Improvement: Add delay after tool swap before warning about wrong speed (#840) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../skyhanni/features/garden/GardenOptimalSpeed.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt index e1a02630a..a057082ad 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -47,6 +48,7 @@ class GardenOptimalSpeed { private var lastWarnTime = 0L private var cropInHand: CropType? = null private var rancherOverlayList: List> = emptyList() + private var lastToolSwitch = SimpleTimeMark.farPast() @SubscribeEvent fun onTick(event: LorenzTickEvent) { @@ -93,6 +95,7 @@ class GardenOptimalSpeed { @SubscribeEvent fun onGardenToolChange(event: GardenToolChangeEvent) { + lastToolSwitch = SimpleTimeMark.now() cropInHand = event.crop optimalSpeed = cropInHand?.getOptimalSpeed() ?: -1 } @@ -138,13 +141,15 @@ class GardenOptimalSpeed { text += " (§eCurrent: §f$currentSpeed" if (sneaking) text += " §7[Sneaking]" text += "§f)" - - if (config.showOnHUD) config.pos.renderString("§c$text", posLabel = "Garden Optimal Speed") - if (sneaking && !sneakingPersistent) return - warn() - } else { - if (config.showOnHUD) config.pos.renderString("§a$text", posLabel = "Garden Optimal Speed") } + + val recentlySwitchedTool = lastToolSwitch.passedSince() < 1.5.seconds + val recentlyStartedSneaking = sneaking && !sneakingPersistent + + val colorCode = if (recentlySwitchedTool || recentlyStartedSneaking) "7" else if (optimalSpeed != currentSpeed) "c" else "a" + + if (config.showOnHUD) config.pos.renderString("§$colorCode$text", posLabel = "Garden Optimal Speed") + if (optimalSpeed != currentSpeed && !recentlySwitchedTool && !recentlyStartedSneaking) warn() } private fun warn() { -- cgit