diff options
5 files changed, 72 insertions, 36 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 3c6061087..80cb6f414 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -215,7 +215,7 @@ class SkyHanniMod { loadModule(AshfangHideDamageIndicator()) loadModule(ItemStars()) loadModule(MinionFeatures()) - loadModule(RealTime()) + loadModule(TimeFeatures()) loadModule(RngMeterInventory()) loadModule(WikiCommand()) loadModule(SendCoordinatedCommand()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java index 00a85b441..1f6745f6c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java @@ -46,19 +46,29 @@ public class MiscConfig { @Expose public Position petDisplayPos = new Position(-330, -15, false, true); + @ConfigOption(name = "Time Features", desc = "") + @Accordion @Expose - @ConfigOption(name = "Time", desc = "") - @ConfigEditorAccordion(id = 1) - public boolean time = false; + public TimeConfig time = new TimeConfig(); - @Expose - @ConfigOption(name = "Real Time", desc = "Display the current computer time, a handy feature when playing in full-screen mode.") - @ConfigEditorBoolean - @ConfigAccordionId(id = 1) - public boolean realTime = false; + public static class TimeConfig { - @Expose - public Position realTimePos = new Position(10, 10, false, true); + @Expose + @ConfigOption(name = "Real Time", desc = "Display the current computer time, a handy feature when playing in full-screen mode.") + @ConfigEditorBoolean + public boolean realTime = false; + + @Expose + public Position realTimePos = new Position(10, 10, false, true); + + @Expose + @ConfigOption(name = "Winter Time", desc = "While on the Winter Island, show a timer until Jerry's Workshop closes.") + @ConfigEditorBoolean + public boolean winterTime = true; + + @Expose + public Position winterTimePos = new Position(10, 10, false, true); + } @ConfigOption(name = "Hide Armor", desc = "") @Accordion 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 diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt index 581585c9a..e79599cae 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.utils +import io.github.moulberry.notenoughupdates.util.SkyBlockTime import java.time.Instant import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds @@ -14,7 +15,9 @@ value class SimpleTimeMark(private val millis: Long) { fun passedSince() = if (millis == 0L) Duration.INFINITE else now() - this - fun isInPast() = !passedSince().isNegative() + fun timeUntil() = -passedSince() + + fun isInPast() = timeUntil().isNegative() override fun toString(): String { if (millis == 0L) return "The Far Past" @@ -28,5 +31,6 @@ value class SimpleTimeMark(private val millis: Long) { fun farPast() = SimpleTimeMark(0) fun Long.asTimeMark() = SimpleTimeMark(this) + fun SkyBlockTime.asTimeMark() = SimpleTimeMark(toMillis()) } }
\ No newline at end of file |