From fe9e6825401abe1309d915a3fa237322b33c6413 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 12 Jun 2023 14:56:58 +0200 Subject: Added composter empty timer for outside garden Added composter soon empty warning for outside garden --- .../java/at/hannibal2/skyhanni/config/Storage.java | 6 +++ .../hannibal2/skyhanni/config/features/Garden.java | 18 +++++++++ .../features/garden/composter/ComposterDisplay.kt | 45 ++++++++++++++++++++-- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index 39b806520..27e9c0cf9 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -186,6 +186,12 @@ public class Storage { @Expose public Map farmingItems = new HashMap<>(); } + + @Expose + public long composterEmptyTime = 0; + + @Expose + public long lastComposterEmptyWarningTime = 0; } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index b1a643f66..01d097338 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -1002,6 +1002,24 @@ public class Garden { @ConfigAccordionId(id = 17) public boolean composterDisplayEnabled = true; + @Expose + @ConfigOption( + name = "Outside Garden", + desc = "Show Time till composter is empty outside garden" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 17) + public boolean composterDisplayOutsideGarden = false; + + @Expose + @ConfigOption( + name = "Composter warning", + desc = "Warn when the composter gets close to empty, even outside garden." + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 17) + public boolean composterWarnAlmostClose = false; + @Expose @ConfigOption( name = "Upgrade Price", diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt index 8f6a34a18..e2f3b6710 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.* import kotlin.time.Duration import kotlin.time.DurationUnit @@ -42,7 +43,7 @@ class ComposterDisplay { @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { - if (!isEnabled()) return + if (!(config.composterDisplayEnabled && GardenAPI.inGarden())) return readData(event.tabList) @@ -97,6 +98,7 @@ class ComposterDisplay { private fun addComposterEmptyTime(emptyTime: Duration?): List { return if (emptyTime != null) { val millis = emptyTime.toDouble(DurationUnit.MILLISECONDS).toLong() + GardenAPI.config?.composterEmptyTime = System.currentTimeMillis() + millis val format = TimeUtils.formatDuration(millis, maxUnits = 2) listOf(NEUItems.getItemStack("BUCKET"), "§b$format") } else { @@ -160,10 +162,47 @@ class ComposterDisplay { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (isEnabled()) { + if (!LorenzUtils.inSkyBlock) return + + if (GardenAPI.inGarden() && config.composterDisplayEnabled) { config.composterDisplayPos.renderStringsAndItems(display, posLabel = "Composter Display") } + + checkWarningsAndOutsideGarden() + } + + private fun checkWarningsAndOutsideGarden() { + val storage = GardenAPI.config ?: return + + val format = if (storage.composterEmptyTime != 0L) { + val duration = storage.composterEmptyTime - System.currentTimeMillis() + if (duration > 0) { + if (duration < 1000 * 60 * 20) { + warn("Your composter in the garden is soon empty!") + } + TimeUtils.formatDuration(duration, maxUnits = 3) + } else { + warn("Your composter is empty!") + "§cComposter is empty!" + } + } else "?" + + if (!GardenAPI.inGarden() && config.composterDisplayOutsideGarden) { + val list = Collections.singletonList(listOf(NEUItems.getItemStack("BUCKET"), "§b$format")) + config.composterDisplayPos.renderStringsAndItems(list, posLabel = "Composter Display") + } } - fun isEnabled() = config.composterDisplayEnabled && GardenAPI.inGarden() + private fun warn(warningMessage: String) { + if (!config.composterWarnAlmostClose) return + val storage = GardenAPI.config ?: return + + if (LorenzUtils.inDungeons) return + if (LorenzUtils.inKuudraFight) return + + if (System.currentTimeMillis() < storage.lastComposterEmptyWarningTime + 1000 * 60 * 2) return + storage.lastComposterEmptyWarningTime = System.currentTimeMillis() + LorenzUtils.chat("§e[SkyHanni] $warningMessage") + TitleUtils.sendTitle("§eComposter Warning!", 3_000) + } } \ No newline at end of file -- cgit