-
-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathColdOverlay.kt
More file actions
54 lines (44 loc) · 2.05 KB
/
ColdOverlay.kt
File metadata and controls
54 lines (44 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package at.hannibal2.skyhanni.features.mining
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.IslandTypeTags
import at.hannibal2.skyhanni.events.ColdUpdateEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.GuiRenderUtils
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.compat.createResourceLocation
import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object ColdOverlay {
private val config get() = SkyHanniMod.feature.mining.coldOverlay
private var cold = 0
private var lastCold = 0
private var lastColdUpdate = SimpleTimeMark.farPast()
private val textureLocation = createResourceLocation("minecraft", "textures/misc/powder_snow_outline.png")
@HandleEvent
fun onGuiRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!isEnabled()) return
val alpha = getColdAlpha()
if (alpha == 0f) return
GuiRenderUtils.drawTexturedRect(0f, 0f, textureLocation, alpha)
}
// TODO fix small bug with high cold and low threshold having the same opacity than high cold and a b it smaller threshold
private fun getColdAlpha(): Float {
val coldInterp = NumberUtil.interpolate(cold.toFloat(), lastCold.toFloat(), lastColdUpdate.toMillis())
val coldPercentage = (coldInterp - config.coldThreshold) / (100 - config.coldThreshold)
return coldPercentage.coerceAtLeast(0f) * (config.maxAlpha / 100)
}
@HandleEvent
fun onColdUpdate(event: ColdUpdateEvent) {
val duration = if (event.cold == 0) 1.seconds else 0.seconds
DelayedRun.runDelayed(duration) {
lastCold = cold
cold = event.cold
lastColdUpdate = SimpleTimeMark.now()
}
}
private fun isEnabled() = IslandTypeTags.IS_COLD.inAny() && config.enabled
}