From 8f8df60eb5f8bc69eb76b385f4298d29ca8ca649 Mon Sep 17 00:00:00 2001 From: efefury <69400149+efefury@users.noreply.github.com> Date: Wed, 12 Apr 2023 21:12:22 +0000 Subject: added notification when organic matter/fuel is low in composter (#40) --- .../skyhanni/features/garden/ComposterDisplay.kt | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden') 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>() 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) { + 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 -- cgit