From cc59cccadf38cb263d5c035ac4f0b74d9adfe1ca Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 29 Aug 2023 12:17:44 +0200 Subject: Added Winter Time --- .../hannibal2/skyhanni/features/misc/RealTime.kt | 24 ----------- .../skyhanni/features/misc/TimeFeatures.kt | 46 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/RealTime.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/TimeFeatures.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/RealTime.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/RealTime.kt deleted file mode 100644 index c5bda78c8..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/RealTime.kt +++ /dev/null @@ -1,24 +0,0 @@ -package at.hannibal2.skyhanni.features.misc - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.text.SimpleDateFormat - -class RealTime { - - private val format = SimpleDateFormat("HH:mm:ss") - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (!isEnabled()) return - - SkyHanniMod.feature.misc.realTimePos.renderString(format.format(System.currentTimeMillis()), posLabel = "Real Time") - } - - private fun isEnabled(): Boolean { - return LorenzUtils.inSkyBlock && SkyHanniMod.feature.misc.realTime - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/TimeFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/TimeFeatures.kt new file mode 100644 index 000000000..e956791bf --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/TimeFeatures.kt @@ -0,0 +1,46 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.RecalculatingValue +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark +import at.hannibal2.skyhanni.utils.TimeUtils.format +import io.github.moulberry.notenoughupdates.util.SkyBlockTime +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.text.SimpleDateFormat +import kotlin.time.Duration.Companion.days +import kotlin.time.Duration.Companion.seconds + +class TimeFeatures { + private val config get() = SkyHanniMod.feature.misc.time + + private val format = SimpleDateFormat("HH:mm:ss") + + private val startOfNextYear = RecalculatingValue(1.seconds) { + SkyBlockTime(year = SkyBlockTime.now().year + 1).asTimeMark() + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!LorenzUtils.inSkyBlock) return + + if (config.realTime) { + config.realTimePos.renderString(format.format(System.currentTimeMillis()), posLabel = "Real Time") + } + + if (config.winterTime && IslandType.WINTER.isInIsland()) { + val timeTillNextYear = startOfNextYear.getValue().timeUntil() + val alreadyInNextYear = timeTillNextYear > 5.days + val text = if (alreadyInNextYear) { + "§fJerry's Workshop §cis closing!" + } else { + "§fJerry's Workshop §ecloses in §b${timeTillNextYear.format()}" + } + config.winterTimePos.renderString(text, posLabel = "Winter Time") + } + } +} \ No newline at end of file -- cgit