From 61368c57bd36f3d6be3d072cfd9bbb24ca8fa090 Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Sat, 9 Dec 2023 16:25:52 -0800 Subject: Feature: Refined Jyrre Boost Timer (#783) Add JyrreTimer for Bottle of Jyrre. #783 --- .../skyhanni/features/event/winter/JyrreTimer.kt | 92 ++++++++++++++++++++++ .../skyhanni/features/garden/GardenAPI.kt | 16 +--- 2 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt new file mode 100644 index 000000000..bee0d1b09 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/winter/JyrreTimer.kt @@ -0,0 +1,92 @@ +package at.hannibal2.skyhanni.features.event.winter + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent +import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.RenderUtils.addItemIcon +import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.concurrent.fixedRateTimer +import kotlin.time.Duration.Companion.minutes +import kotlin.time.Duration.Companion.seconds + +class JyrreTimer { + private val config get() = SkyHanniMod.feature.event.winter.jyrreTimer + private val drankBottlePattern by RepoPattern.pattern( + "event.winter.drank.jyrre", + "§aYou drank a §r§6Refined Bottle of Jyrre §r§aand gained §r§b\\+300✎ Intelligence §r§afor §r§b60 minutes§r§a!" + ) + private var display = emptyList() + private var duration = 0.seconds + + init { + fixedRateTimer(name = "skyhanni-update-jyrre-display", period = 1000L) { + try { + updateJyrreDisplay() + } catch (error: Throwable) { + ErrorManager.logErrorWithData(error, "Error Updating Jyrre Timer") + } + } + } + + @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + resetDisplay() + } + + private fun resetDisplay() { + display = if (config.showInactive) drawDisplay() else emptyList() + duration = 0.seconds + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!isEnabled() || !drankBottlePattern.matches(event.message)) return + duration = 60.minutes + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { + if (!isEnabled()) return + config.pos.renderSingleLineWithItems(display, posLabel = "Refined Jyrre Timer") + } + + private fun updateJyrreDisplay() { + if (!isEnabled()) return + + if (display.isNotEmpty() && !config.showInactive && duration <= 0.seconds) { + resetDisplay() + return + } + + display = drawDisplay() + } + + private val displayIcon by lazy { "REFINED_BOTTLE_OF_JYRRE".asInternalName().getItemStack() } + + fun drawDisplay(): MutableList { + duration -= 1.seconds + + return mutableListOf().apply { + addItemIcon(displayIcon) + add("§aJyrre Boost: ") + + if (duration <= 0.seconds && config.showInactive) { + add("§cInactive!") + } else { + val format = TimeUtils.formatDuration(duration) + add("§b$format") + } + } + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index 6ef4800dc..7fba5b56a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -31,10 +31,10 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.RenderUtils.addItemIcon import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCultivatingCounter import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHoeCounter import net.minecraft.client.Minecraft -import net.minecraft.enchantment.Enchantment import net.minecraft.item.ItemStack import net.minecraft.network.play.client.C09PacketHeldItemChange import net.minecraft.util.AxisAlignedBB @@ -143,18 +143,8 @@ object GardenAPI { fun readCounter(itemStack: ItemStack): Long = itemStack.getHoeCounter() ?: itemStack.getCultivatingCounter() ?: -1L - fun MutableList.addCropIcon(crop: CropType, highlight: Boolean = false) { - try { - var icon = crop.icon.copy() - if (highlight) { - // Hack to add enchant glint, like Hypixel does it - icon.addEnchantment(Enchantment.protection, 0) - } - add(icon) - } catch (e: NullPointerException) { - e.printStackTrace() - } - } + fun MutableList.addCropIcon(crop: CropType, highlight: Boolean = false) = + addItemIcon(crop.icon.copy(), highlight) fun hideExtraGuis() = ComposterOverlay.inInventory || AnitaMedalProfit.inInventory || SkyMartCopperPrice.inInventory || FarmingContestAPI.inInventory || VisitorAPI.inInventory || FFGuideGUI.isInGui() -- cgit