diff options
author | efefury <69400149+efefury@users.noreply.github.com> | 2023-04-12 21:12:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-12 23:12:22 +0200 |
commit | 8f8df60eb5f8bc69eb76b385f4298d29ca8ca649 (patch) | |
tree | be9dd5308cc04c96ceff75f5ebaf12eb9e09cc31 /src/main/java/at/hannibal2 | |
parent | 5021f7d8d9403a84c9df0ca6e1ac279c30c3c879 (diff) | |
download | skyhanni-8f8df60eb5f8bc69eb76b385f4298d29ca8ca649.tar.gz skyhanni-8f8df60eb5f8bc69eb76b385f4298d29ca8ca649.tar.bz2 skyhanni-8f8df60eb5f8bc69eb76b385f4298d29ca8ca649.zip |
added notification when organic matter/fuel is low in composter (#40)
Diffstat (limited to 'src/main/java/at/hannibal2')
5 files changed, 98 insertions, 17 deletions
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 4ac5450ba..6fbe69ad2 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -746,9 +746,6 @@ public class Garden { public boolean composterHighLightUpgrade = true; @Expose - public Position composterDisplayPos = new Position(-363, 13, false, true); - - @Expose @ConfigOption( name = "Inventory Numbers", desc = "Show the amount of Organic Matter, Fuel and Composts Available while inside the composter inventory." @@ -758,6 +755,47 @@ public class Garden { public boolean composterInventoryNumbers = true; @Expose + @ConfigOption(name = "Notification When Low Composter", desc = "") + @ConfigAccordionId(id = 17) + @ConfigEditorAccordion(id = 21) + public boolean composterNotifyLow = false; + + @Expose + @ConfigOption(name = "Enable", desc = "Show a notification when organic matter or fuel runs low in your composter.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 21) + public boolean composterNotifyLowEnabled = true; + + @Expose + @ConfigOption(name = "Show Title", desc = "Send a title to notify.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 21) + public boolean composterNotifyLowTitle = false; + + @Expose + @ConfigOption(name = "Min Organic Matter", desc = "Warn when Organic Matter is below this value.") + @ConfigEditorSlider( + minValue = 1_000, + maxValue = 80_000, + minStep = 1 + ) + @ConfigAccordionId(id = 21) + public int composterNotifyLowOrganicMatter = 20_000; + + @Expose + @ConfigOption(name = "Min Fuel Cap", desc = "Warn when Fuel is below this value.") + @ConfigEditorSlider( + minValue = 500, + maxValue = 40_000, + minStep = 1 + ) + @ConfigAccordionId(id = 21) + public int composterNotifyLowFuel = 10_000; + + @Expose + public Position composterDisplayPos = new Position(-363, 13, false, true); + + @Expose @ConfigOption(name = "True Farming Fortune", desc = "") @ConfigEditorAccordion(id = 18) public boolean farmingFortune = false; @@ -828,6 +866,7 @@ public class Garden { @ConfigEditorBoolean public boolean deskInSkyBlockMenu = true; + @Expose @ConfigOption(name = "Fungi Cutter Warning", desc = "Warn when breaking mushroom with the wrong Fungi Cutter mode.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java index 59133d122..4638f816d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java @@ -54,6 +54,12 @@ public class Hidden { public Map<String, Integer> gardenDicerRngDrops = new HashMap<>(); @Expose + public long informedAboutLowMatter = 0; + + @Expose + public long informedAboutLowFuel = 0; + + @Expose public Map<Long, List<CropType>> gardenJacobFarmingContestTimes = new HashMap<>(); @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt index e80551dec..d910a26bc 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -182,15 +183,3 @@ class SkillExperience { } } -private fun String.formatNumber(): Long { - var text = replace(",", "") - val multiplier = if (text.endsWith("k")) { - text = text.substring(0, text.length - 1) - 1_000 - } else if (text.endsWith("m")) { - text = text.substring(0, text.length - 1) - 1_000_000 - } else 1 - val d = text.toDouble() - return (d * multiplier).toLong() -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt index 7f37c6867..23316166f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt @@ -1,24 +1,28 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.SendTitleHelper import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern class ComposterDisplay { private val config get() = SkyHanniMod.feature.garden + private val hidden get() = SkyHanniMod.feature.hidden private var display = listOf<List<Any>>() 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"), - ; + STORED_COMPOST(" Stored Compost: §r(.*)", "COMPOST"); val displayItem by lazy { NEUItems.getItemStack(icon) @@ -71,6 +75,36 @@ class ComposterDisplay { newList.add(DataType.STORED_COMPOST.addToList(data)) display = newList + + notify(data) + } + + private fun notify(data: MutableMap<DataType, String>) { + if (!config.composterNotifyLowEnabled) return + + data[DataType.ORGANIC_MATTER]?.removeColor()?.formatNumber()?.let { + if (it <= config.composterNotifyLowOrganicMatter) { + if (System.currentTimeMillis() >= hidden.informedAboutLowMatter) { + if (config.composterNotifyLowTitle) { + SendTitleHelper.sendTitle("§cYour Organic Matter is low", 4_000) + } + LorenzUtils.chat("§e[SkyHanni] §cYour Organic Matter is low!") + hidden.informedAboutLowMatter = System.currentTimeMillis() + 30_000 + } + } + } + + data[DataType.FUEL]?.removeColor()?.formatNumber()?.let { + if (it <= config.composterNotifyLowFuel && + System.currentTimeMillis() >= hidden.informedAboutLowFuel + ) { + if (config.composterNotifyLowTitle) { + SendTitleHelper.sendTitle("§cYour Fuel is low", 4_000) + } + LorenzUtils.chat("§e[SkyHanni] §cYour Fuel is low!") + hidden.informedAboutLowFuel = System.currentTimeMillis() + 30_000 + } + } } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt index a3c86c0f4..0d09ea81d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt @@ -177,4 +177,17 @@ object NumberUtil { else -> LorenzColor.RED } } + + fun String.formatNumber(): Long { + var text = replace(",", "") + val multiplier = if (text.endsWith("k")) { + text = text.substring(0, text.length - 1) + 1_000 + } else if (text.endsWith("m")) { + text = text.substring(0, text.length - 1) + 1_000_000 + } else 1 + val d = text.toDouble() + return (d * multiplier).toLong() + } }
\ No newline at end of file |