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/data/MiningAPI.kt | |
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/data/MiningAPI.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt new file mode 100644 index 000000000..89ebe71d6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt @@ -0,0 +1,70 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.ColdUpdateEvent +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.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.SimpleTimeMark +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.seconds + +object MiningAPI { + + private val group = RepoPattern.group("data.miningapi") + private val glaciteAreaPattern by group.pattern("area.glacite", "Glacite Tunnels") + val coldReset by group.pattern( + "cold.reset", + "§cThe warmth of the campfire reduced your §r§b❄ Cold §r§cto 0!|§c ☠ §r§7You froze to death§r§7." + ) + + private var cold = 0 + var lastColdUpdate = SimpleTimeMark.farPast() + var lastColdReset = SimpleTimeMark.farPast() + + fun inGlaciteArea() = glaciteAreaPattern.matches(HypixelData.skyBlockArea) || IslandType.MINESHAFT.isInIsland() + + fun inColdIsland() = IslandType.DWARVEN_MINES.isInIsland() || IslandType.MINESHAFT.isInIsland() + + fun getCold() = cold + + @SubscribeEvent + fun onScoreboardChange(event: ScoreboardChangeEvent) { + val newCold = event.newList.matchFirst(ScoreboardPattern.coldPattern) { + group("cold").toInt().absoluteValue + } ?: return + + if (newCold != cold) { + updateCold(newCold) + } + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!inColdIsland()) return + if (coldReset.matches(event.message)) { + updateCold(0) + lastColdReset = SimpleTimeMark.now() + } + } + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + if (cold != 0) updateCold(0) + lastColdReset = SimpleTimeMark.now() + } + + private fun updateCold(newCold: Int) { + // Hypixel sends cold data once in scoreboard even after resetting it + if (cold == 0 && lastColdUpdate.passedSince() < 1.seconds) return + lastColdUpdate = SimpleTimeMark.now() + ColdUpdateEvent(newCold).postAndCatch() + cold = newCold + } + +} |