From 8f57726ec406f8f8056ef54f11051a2bfbd1a69e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 29 Mar 2023 20:55:13 +0200 Subject: Added Composter Compact Display - Displays the compost data from the tab list in a compact form as gui element --- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 1 + .../hannibal2/skyhanni/config/features/Garden.java | 15 ++++ .../skyhanni/features/garden/ComposterDisplay.kt | 82 ++++++++++++++++++++++ .../features/garden/GardenNextJacobContest.kt | 27 +++++-- 4 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 1d5281b60..a242ccbc8 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -234,6 +234,7 @@ public class SkyHanniMod { loadModule(new GardenVisitorColorNames()); loadModule(new GardenTeleportPadCompactName()); loadModule(new AnitaMedalProfit()); + loadModule(new ComposterDisplay()); Commands.INSTANCE.init(); 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 aba49896a..dd78c3095 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -602,7 +602,22 @@ public class Garden { @Expose public Position anitaMedalProfitPos = new Position(206, 158, false, true); + @Expose + @ConfigOption(name = "Composter", desc = "") + @ConfigEditorAccordion(id = 16) + public boolean composter = false; + @Expose + @ConfigOption( + name = "Compact Display", + desc = "Displays the compost data from the tab list in a compact form as gui element." + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 16) + public boolean composterDisplayEnabled = true; + + @Expose + public Position composterDisplayPos = new Position(-363, 13, false, true); @Expose @ConfigOption(name = "Plot Price", desc = "Show the price of the plot in coins when inside the Configure Plots inventory.") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt new file mode 100644 index 000000000..7c2b92ebd --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt @@ -0,0 +1,82 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class ComposterDisplay { + private val config get() = SkyHanniMod.feature.garden + private var display = listOf>() + + enum class DataType(val pattern: String, val icon: String) { + ORGANIC_MATTER(" Organic Matter: §r(.*)", "WHEAT"), + FUEL(" Fuel: §r(.*)", "OIL_BARREL"), + TIME_LEFT(" Time Left: §r(.*)", "WATCH"), + STORED_COMPOST(" Stored Compost: §r(.*)", "COMPOST"), + ; + + val displayItem by lazy { + NEUItems.getItemStack(icon) + } + + fun addToList(map: Map): List { + return listOf(displayItem, map[this]!!) + } + } + + @SubscribeEvent + fun onTabListUpdate(event: TabListUpdateEvent) { + if (!isEnabled()) return + + var next = false + println(" ") + val data = mutableMapOf() + + for (line in event.tabList) { + if (line == "§b§lComposter:") { + next = true + continue + } + if (next) { + if (line == "") break + for (type in DataType.values()) { + val pattern = Pattern.compile(type.pattern) + val matcher = pattern.matcher(line) + if (matcher.matches()) { + data[type] = matcher.group(1) + } + } + println("'$line'") + } + } + + val newList = mutableListOf>() + newList.addAsSingletonList("§bComposter") + + newList.add(DataType.TIME_LEFT.addToList(data)) + + val list = mutableListOf() + list.addAll(DataType.ORGANIC_MATTER.addToList(data)) + list.add(" ") + list.addAll(DataType.FUEL.addToList(data)) + newList.add(list) + + newList.add(DataType.STORED_COMPOST.addToList(data)) + + display = newList + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (isEnabled()) { + config.composterDisplayPos.renderStringsAndItems(display, posLabel = "Composter Display") + } + } + + fun isEnabled() = config.composterDisplayEnabled && GardenAPI.inGarden() +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt index c35d5cd01..9347cb488 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -1,10 +1,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.ConfigLoadEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.InventoryCloseEvent -import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils @@ -28,6 +25,27 @@ class GardenNextJacobContest { private val maxContestsPerYear = 124 private val contestDuration = 1_000 * 60 * 20 + @SubscribeEvent + fun onTabListUpdate(event: TabListUpdateEvent) { + if (!isEnabled()) return + + var next = false + val newList = mutableListOf() + for (line in event.tabList) { + if (line == "§b§lComposter:") { + newList.add(line) + next = true + continue + } + if (next) { + if (line == "") break + newList.add(line) + } + } + + display = newList + } + @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { if (!isEnabled()) return @@ -137,6 +155,7 @@ class GardenNextJacobContest { } if (contests.isEmpty()) { + list.add("§cOpen calendar to read jacob contest times!") return list } -- cgit