diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 12:34:18 +0200 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 12:34:18 +0200 |
| commit | 4293cfd919c3c93d4532534f722c407d7ad1370d (patch) | |
| tree | f9f612f021ef7f4283d74312edfaca30badc6749 /src/main/java/at/hannibal2/skyhanni/features/event/anniversary | |
| parent | 538e3ceb76f8e0b590291ce9aa90aa94896cdcb6 (diff) | |
| parent | 024ba52fb69b6cd44b4e31542867f802de656f15 (diff) | |
| download | SkyHanni-cum.tar.gz SkyHanni-cum.tar.bz2 SkyHanni-cum.zip | |
Merge branch 'beta' into cumcum
# Conflicts:
# src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
# src/main/java/at/hannibal2/skyhanni/config/features/AshfangConfig.java
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/event/anniversary')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/event/anniversary/ActivePlayerTimer.kt | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/ActivePlayerTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/ActivePlayerTimer.kt new file mode 100644 index 000000000..a83def532 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/ActivePlayerTimer.kt @@ -0,0 +1,76 @@ +package at.hannibal2.skyhanni.features.event.anniversary + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems +import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.SoundUtils.playSound +import at.hannibal2.skyhanni.utils.TimeMark +import at.hannibal2.skyhanni.utils.TimeUtils.format +import at.hannibal2.skyhanni.utils.renderables.Renderable +import io.github.moulberry.notenoughupdates.util.SkyBlockTime +import net.minecraft.init.Items +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.time.Instant +import kotlin.time.Duration.Companion.minutes +import kotlin.time.Duration.Companion.seconds + +object ActivePlayerTimer { + val displayItem by lazy { NEUItems.getItemStackOrNull("EPOCH_CAKE_ORANGE") ?: ItemStack(Items.clock) } + + private var lastTimerReceived = TimeMark.never() + private var lastTimeAlerted = TimeMark.never() + + private var overlay: List<Any>? = null + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (event.message == "§6§lACTIVE PLAYER! §eYou gained §b+1 Raffle Ticket§e!") { + lastTimerReceived = TimeMark.now() + } + } + + fun isEnabled(): Boolean { + return SkyHanniMod.feature.misc.century.enableActiveTimer && + Instant.now().isBefore(SkyBlockTime(301).toInstant()) && + LorenzUtils.inSkyBlock + } + + + @SubscribeEvent + fun onRender(event: GuiRenderEvent.GameOverlayRenderEvent) { + SkyHanniMod.feature.misc.century.activeTimerPosition.renderSingleLineWithItems( + overlay ?: return, + posLabel = "300þ Anniversary Active Timer" + ) + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled()) { + overlay = null + return + } + val p = lastTimerReceived.passedTime() + val timeLeft = if (p > 20.minutes) { + 0.seconds + } else { + 20.minutes - p + } + if (p.isFinite() && timeLeft < 1.seconds && lastTimeAlerted.passedTime() > 5.minutes && SkyHanniMod.feature.misc.century.enableActiveAlert) { + SoundUtils.centuryActiveTimerAlert.playSound() + lastTimeAlerted = TimeMark.now() + } + overlay = listOf( + Renderable.itemStack(displayItem), + Renderable.string("§eTime Left: ${timeLeft.format()}") + ) + } + + +}
\ No newline at end of file |
