aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-03-24 00:53:25 +0100
committerGitHub <noreply@github.com>2024-03-24 00:53:25 +0100
commit384d399ee67e5a779969e1c2483893d139da77eb (patch)
tree9737ae320ac361b75f87653f30194c60c54a023f /src/main/java/at
parent46c973abbaafdc814b3aa0a9627fe655464e339d (diff)
downloadskyhanni-384d399ee67e5a779969e1c2483893d139da77eb.tar.gz
skyhanni-384d399ee67e5a779969e1c2483893d139da77eb.tar.bz2
skyhanni-384d399ee67e5a779969e1c2483893d139da77eb.zip
Fix: Lane Switch Warning (part 5) (#1245)
Co-authored-by: Alexia Luna <me@alexia.lol> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/lane/FarmingLaneFeatures.kt67
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt22
2 files changed, 68 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/lane/FarmingLaneFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/lane/FarmingLaneFeatures.kt
index adbd2b9d2..a6a1aaebe 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/lane/FarmingLaneFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/lane/FarmingLaneFeatures.kt
@@ -36,10 +36,18 @@ object FarmingLaneFeatures {
private var display = listOf<String>()
private var timeRemaining: Duration? = null
private var lastSpeed = 0.0
- private var validSpeed = false
private var lastTimeFarming = SimpleTimeMark.farPast()
private var lastPlaySound = SimpleTimeMark.farPast()
private var lastDirection = 0
+ private var movementState = MovementState.CALCULATING
+
+ enum class MovementState(val label: String) {
+ NOT_MOVING("§ePaused"),
+ TOO_SLOW("§cToo slow!"),
+ CALCULATING("§aCalculating.."),
+ NORMAL(""),
+ ;
+ }
@SubscribeEvent
fun onFarmingLaneSwitch(event: FarmingLaneSwitchEvent) {
@@ -67,10 +75,18 @@ object FarmingLaneFeatures {
if (config.distanceDisplay) {
display = buildList {
add("§7Distance until switch: §e${currentDistance.round(1)}")
- val color = if (validSpeed) "§b" else "§8"
+
+ val normal = movementState == MovementState.NORMAL
+ val color = if (normal) "§b" else "§8"
val timeRemaining = timeRemaining ?: return@buildList
val format = timeRemaining.format(showMilliSeconds = timeRemaining < 20.seconds)
- add("§7Time remaining: $color$format")
+ val suffix = if (!normal) {
+ " §7(${movementState.label}§7)"
+ } else ""
+ add("§7Time remaining: $color$format$suffix")
+ if (MovementSpeedDisplay.usingSoulsandSpeed) {
+ add("§7Using inaccurate soul sand speed!")
+ }
}
}
}
@@ -131,23 +147,14 @@ object FarmingLaneFeatures {
}
}
+ private var sameSpeedCounter = 0
+
private fun calculateSpeed(): Boolean {
- val speedPerSecond = MovementSpeedDisplay.speedInLastTick.round(2)
- if (speedPerSecond == 0.0) return false
- val speedTooSlow = speedPerSecond < 1
- if (speedTooSlow) {
- validSpeed = false
- return false
- }
- // only calculate the time if the speed has not changed
- if (lastSpeed != speedPerSecond) {
- lastSpeed = speedPerSecond
- validSpeed = false
- return false
- }
- validSpeed = true
+ val speed = MovementSpeedDisplay.speed.round(2)
+ movementState = calculateMovementState(speed)
+ if (movementState != MovementState.NORMAL) return false
- val timeRemaining = (currentDistance / speedPerSecond).seconds
+ val timeRemaining = (currentDistance / speed).seconds
FarmingLaneFeatures.timeRemaining = timeRemaining
val warnAt = config.laneSwitchNotification.secondsBefore.seconds
if (timeRemaining >= warnAt) {
@@ -159,6 +166,30 @@ object FarmingLaneFeatures {
return lastTimeFarming.passedSince() < warnAt
}
+ private fun calculateMovementState(speed: Double): MovementState {
+ if (lastSpeed != speed) {
+ lastSpeed = speed
+ sameSpeedCounter = 0
+ }
+ sameSpeedCounter++
+
+ if (speed == 0.0 && sameSpeedCounter > 1) {
+ return MovementState.NOT_MOVING
+ }
+ val speedTooSlow = speed < 1
+ if (speedTooSlow && sameSpeedCounter > 5) {
+ return MovementState.TOO_SLOW
+ }
+ // only calculate the time if the speed has not changed
+ if (!MovementSpeedDisplay.usingSoulsandSpeed) {
+ if (sameSpeedCounter < 6) {
+ return MovementState.CALCULATING
+ }
+ }
+
+ return MovementState.NORMAL
+ }
+
@SubscribeEvent
fun onRenderWorld(event: LorenzRenderWorldEvent) {
if (!GardenAPI.inGarden()) return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt
index 671f34606..2a984aeed 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt
@@ -3,11 +3,14 @@ package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.enums.OutsideSbFeature
import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt
+import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import net.minecraft.client.Minecraft
+import net.minecraft.init.Blocks
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.concurrent.fixedRateTimer
@@ -16,9 +19,11 @@ class MovementSpeedDisplay {
private val config get() = SkyHanniMod.feature.misc
private var display = ""
+ private val soulsandSpeeds = mutableListOf<Double>()
companion object {
- var speedInLastTick = 0.0
+ var speed = 0.0
+ var usingSoulsandSpeed = false
}
init {
@@ -30,15 +35,26 @@ class MovementSpeedDisplay {
private fun checkSpeed() {
if (!LorenzUtils.onHypixel) return
- speedInLastTick = with(Minecraft.getMinecraft().thePlayer) {
+ speed = with(Minecraft.getMinecraft().thePlayer) {
val oldPos = LorenzVec(prevPosX, prevPosY, prevPosZ)
val newPos = LorenzVec(posX, posY, posZ)
// Distance from previous tick, multiplied by TPS
oldPos.distance(newPos) * 20
}
+ val movingOnSoulsand = LocationUtils.playerLocation().getBlockAt() == Blocks.soul_sand && speed > 0.0
+ if (movingOnSoulsand) {
+ soulsandSpeeds.add(speed)
+ if (soulsandSpeeds.size > 6) {
+ speed = soulsandSpeeds.average()
+ soulsandSpeeds.removeAt(0)
+ }
+ } else {
+ soulsandSpeeds.clear()
+ }
+ usingSoulsandSpeed = movingOnSoulsand && soulsandSpeeds.size == 6
if (isEnabled()) {
- display = "Movement Speed: ${speedInLastTick.round(2)}"
+ display = "Movement Speed: ${speed.round(2)}"
}
}