diff options
| author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-04-17 18:14:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-17 18:14:16 +0200 |
| commit | 734fdf613cc660430447adbd3191b5bc7c1817de (patch) | |
| tree | 28d6f09db94148a2ec98dd4c9189bef0290ad5b1 /src/main/java/at/hannibal2/skyhanni/features | |
| parent | 6c968778dab9c04b0ff4fec7b4eb61f36e23660d (diff) | |
| download | skyhanni-734fdf613cc660430447adbd3191b5bc7c1817de.tar.gz skyhanni-734fdf613cc660430447adbd3191b5bc7c1817de.tar.bz2 skyhanni-734fdf613cc660430447adbd3191b5bc7c1817de.zip | |
Feature: Cold Overlay (#1438)
Co-authored-by: martimavocado <39881008+martimavocado@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Empa <42304516+ItsEmpa@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
4 files changed, 83 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt index 5cd86d99e..50a51042b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt @@ -56,7 +56,7 @@ class RenderBackground { GlStateManager.pushAttrib() GlStateManager.color(1f, 1f, 1f, 1f) - + GL11.glDepthMask(false) if (backgroundConfig.enabled) { if (backgroundConfig.useCustomBackgroundImage) { @@ -81,7 +81,7 @@ class RenderBackground { ) } } - + GL11.glDepthMask(true) GlStateManager.popMatrix() GlStateManager.popAttrib() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt index e9b4df0a9..b2187a4bd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.data.HypixelData.Companion.getPlayersOnCurrentServe import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.MaxwellAPI import at.hannibal2.skyhanni.data.MayorAPI +import at.hannibal2.skyhanni.data.MiningAPI.getCold import at.hannibal2.skyhanni.data.PartyAPI import at.hannibal2.skyhanni.data.PurseAPI import at.hannibal2.skyhanni.data.QuiverAPI @@ -449,11 +450,11 @@ private fun getHeatShowWhen() = inAnyIsland(IslandType.CRYSTAL_HOLLOWS) && ScoreboardData.sidebarLinesFormatted.any { ScoreboardPattern.heatPattern.matches(it) } private fun getColdDisplayPair(): List<ScoreboardElementType> { - val cold = getGroupFromPattern(ScoreboardData.sidebarLinesFormatted, ScoreboardPattern.coldPattern, "cold") + val cold = -getCold() return listOf( when { - informationFilteringConfig.hideEmptyLines && cold == "0" -> "<hidden>" + informationFilteringConfig.hideEmptyLines && cold == 0 -> "<hidden>" displayConfig.displayNumbersFirst -> "§b$cold❄ Cold" else -> "Cold: §b$cold❄" } to HorizontalAlignment.LEFT diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/ColdOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/ColdOverlay.kt new file mode 100644 index 000000000..196f2f6fb --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/ColdOverlay.kt @@ -0,0 +1,67 @@ +package at.hannibal2.skyhanni.features.mining + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.MiningAPI.inColdIsland +import at.hannibal2.skyhanni.events.ColdUpdateEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.RenderUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.util.ResourceLocation +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.opengl.GL11 +import kotlin.time.Duration.Companion.seconds + +class 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 by lazy { ResourceLocation("skyhanni", "cold_overlay.png") } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { + if (!isEnabled()) return + val alpha = getColdAlpha() + if (alpha == 0f) return + + Minecraft.getMinecraft().textureManager.bindTexture(textureLocation) + + GlStateManager.pushMatrix() + GlStateManager.pushAttrib() + + GL11.glDepthMask(false) + GlStateManager.translate(0f, 0f, -500f) + GlStateManager.color(1f, 1f, 1f, alpha) + + RenderUtils.drawTexturedRect(0f, 0f) + GL11.glDepthMask(true) + + GlStateManager.popMatrix() + GlStateManager.popAttrib() + } + + 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) + } + + @SubscribeEvent + 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() = inColdIsland() && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt index acaa23ff5..d018deaa9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt @@ -1,21 +1,19 @@ package at.hannibal2.skyhanni.features.mining import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.MiningAPI.getCold +import at.hannibal2.skyhanni.data.MiningAPI.inColdIsland +import at.hannibal2.skyhanni.data.MiningAPI.lastColdReset +import at.hannibal2.skyhanni.events.ColdUpdateEvent import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.ScoreboardChangeEvent -import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern import at.hannibal2.skyhanni.utils.ConditionalUtils import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.math.absoluteValue import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @@ -28,9 +26,7 @@ object MiningNotifications { DIAMOND_GOBLIN("§bDiamond Goblin", "§bDiamond Goblin"), COLD("§bCold", "§bCold"); - override fun toString(): String { - return str - } + override fun toString() = str } private val patternGroup = RepoPattern.group("mining.notifications") @@ -50,16 +46,10 @@ object MiningNotifications { "goblin.diamondspawn", "§6A §r§bDiamond Goblin §r§6has spawned!" ) - private val coldReset by patternGroup.pattern( - "cold.reset", - "§cThe warmth of the campfire reduced your §r§b❄ Cold §r§cto 0!" - ) private val config get() = SkyHanniMod.feature.mining.notifications - private var cold = 0 private var hasSentCold = false - private var coldResetTimer = SimpleTimeMark.farPast() @SubscribeEvent fun onChat(event: LorenzChatEvent) { @@ -71,25 +61,16 @@ object MiningNotifications { scrapDrop.matches(message) -> sendNotification(MiningNotificationList.SCRAP) goldenGoblinSpawn.matches(message) -> sendNotification(MiningNotificationList.GOLDEN_GOBLIN) diamondGoblinSpawn.matches(message) -> sendNotification(MiningNotificationList.DIAMOND_GOBLIN) - coldReset.matches(message) -> { - cold = 0 - hasSentCold = false - coldResetTimer = SimpleTimeMark.now().plus(1.seconds) - } } } @SubscribeEvent - fun onScoreboardChange(event: ScoreboardChangeEvent) { - if (!LorenzUtils.inAnyIsland(IslandType.DWARVEN_MINES, IslandType.MINESHAFT)) return + fun onColdUpdate(event: ColdUpdateEvent) { + if (!inColdIsland()) return if (!config.enabled) return - val newCold = event.newList.matchFirst(ScoreboardPattern.coldPattern) { - group("cold").toInt().absoluteValue - } ?: 0 - if (cold == newCold) return - cold = newCold - if (coldResetTimer.isInFuture()) return - if (cold >= config.coldThreshold.get() && !hasSentCold) { + if (lastColdReset.passedSince() < 1.seconds) return + + if (event.cold >= config.coldThreshold.get() && !hasSentCold) { hasSentCold = true sendNotification(MiningNotificationList.COLD) } @@ -97,14 +78,13 @@ object MiningNotifications { @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { - cold = 0 hasSentCold = false } @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { ConditionalUtils.onToggle(config.coldThreshold) { - if (cold != config.coldThreshold.get()) hasSentCold = false + if (getCold() != config.coldThreshold.get()) hasSentCold = false } } |
