aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authoralexia <me@alexia.lol>2024-01-18 17:10:24 +0100
committerGitHub <noreply@github.com>2024-01-18 17:10:24 +0100
commit1f76e3ac81571dca35b710df62de25e8f4956da2 (patch)
treeb69024bf6f16d5de657191be708cd254e5cd43e2 /src/main/java/at/hannibal2
parent9827e764ea8e686d8e0a7b1d5b320da7ce85c227 (diff)
downloadskyhanni-1f76e3ac81571dca35b710df62de25e8f4956da2.tar.gz
skyhanni-1f76e3ac81571dca35b710df62de25e8f4956da2.tar.bz2
skyhanni-1f76e3ac81571dca35b710df62de25e8f4956da2.zip
Check if sneaking for optimal speed in garden (#898)
Check if sneaking for optimal speed in garden and show current speed when wrong. #898
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt34
1 files changed, 31 insertions, 3 deletions
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 9e83f8ba8..3e5888868 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.GardenToolChangeEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign
@@ -15,12 +16,21 @@ import net.minecraft.client.gui.inventory.GuiEditSign
import net.minecraftforge.client.event.GuiOpenEvent
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
class GardenOptimalSpeed {
private val config get() = GardenAPI.config.optimalSpeeds
private val configCustomSpeed get() = config.customSpeed
- private var currentSpeed = 100
+ private var sneakingTime = 0.seconds
+ private val sneaking get() = Minecraft.getMinecraft().thePlayer.isSneaking
+ private val sneakingPersistent get() = sneakingTime > 5.seconds
+ private var _currentSpeed = 100
+ private var currentSpeed: Int
+ get() = (_currentSpeed * (if (sneaking) 0.3 else 1.0)).toInt()
+ set(value) {
+ _currentSpeed = value
+ }
private var optimalSpeed = -1
private val currentSpeedPattern = " Speed: §r§f✦(?<speed>.*)".toPattern()
private var lastWarnTime = 0L
@@ -28,6 +38,15 @@ class GardenOptimalSpeed {
private var rancherOverlayList: List<List<Any?>> = emptyList()
@SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (sneaking) {
+ sneakingTime += 50.milliseconds
+ } else {
+ sneakingTime = 0.seconds
+ }
+ }
+
+ @SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
for (line in event.tabList) {
currentSpeedPattern.matchMatcher(line) {
@@ -84,9 +103,14 @@ class GardenOptimalSpeed {
if (GardenAPI.hideExtraGuis()) return
- val text = "Optimal Speed: §f$optimalSpeed"
+ var text = "Optimal Speed: §f$optimalSpeed"
if (optimalSpeed != currentSpeed) {
+ 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")
@@ -102,7 +126,11 @@ class GardenOptimalSpeed {
lastWarnTime = System.currentTimeMillis()
LorenzUtils.sendTitle("§cWrong speed!", 3.seconds)
cropInHand?.let {
- LorenzUtils.chat("Wrong speed for ${it.cropName}: §f$currentSpeed §e(§f$optimalSpeed §eis optimal)")
+ var text = "Wrong speed for ${it.cropName}: §f$currentSpeed"
+ if (sneaking) text += " §7[Sneaking]"
+ text += " §e(§f$optimalSpeed §eis optimal)"
+
+ LorenzUtils.chat(text)
}
}