From f04c77ffe77cc76de6023e07c229162c52c52449 Mon Sep 17 00:00:00 2001 From: martimavocado Date: Wed, 19 Jun 2024 19:30:43 +0100 Subject: [PATCH 1/2] raven code successfully copied --- .../inventory/helper/HelperConfig.java | 6 ++ .../inventory/experiments/GuardianReminder.kt | 87 +++++++++++++++++++ .../{ => experiments}/UltraRareBookAlert.kt | 2 +- 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt rename src/main/java/at/hannibal2/skyhanni/features/inventory/{ => experiments}/UltraRareBookAlert.kt (98%) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java index 990399d62b89..53c70ed1a753 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java @@ -69,6 +69,12 @@ public static class EnchantingConfig { @ConfigEditorBoolean @FeatureToggle public boolean ultraRareBookAlert = false; + + @Expose + @ConfigOption(name = "Guardian Reminder", desc = "Sends a warning when opening the experimentation table") + @ConfigEditorBoolean + @FeatureToggle + public boolean guardianReminder = false; } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt new file mode 100644 index 000000000000..d55f4e364703 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt @@ -0,0 +1,87 @@ +package at.hannibal2.skyhanni.features.inventory.experiments + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.PetAPI +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.RenderUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiContainer +import net.minecraft.client.renderer.GlStateManager +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color +import kotlin.time.Duration.Companion.seconds + +@SkyHanniModule +object GuardianReminder { + + private val config get() = SkyHanniMod.feature.inventory.helper.enchanting + private var lastNotificationTime = SimpleTimeMark.farPast() + private var hasSentSound = false + + private val patternGroup = RepoPattern.group("data.enchanting.inventory.experimentstable") + private val inventoryNamePattern by patternGroup.pattern( + "mainmenu", + "Experimentation Table", + ) + private val petNamePattern by patternGroup.pattern( + "guardianpet", + "§[56d]Guardian", + ) + + @SubscribeEvent + fun onInventory(event: InventoryFullyOpenedEvent) { + if (!isEnabled()) return + if (!inventoryNamePattern.matches(event.inventoryName)) return + if (petNamePattern.matches(PetAPI.currentPet)) return + + lastNotificationTime = SimpleTimeMark.now() + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + if (hasSentSound) hasSentSound = false + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (!isEnabled()) return + if (!inventoryNamePattern.matches(InventoryUtils.openInventoryName())) return + if (lastNotificationTime.passedSince() > 2.seconds) return + val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return + + sendTitle(gui.width, gui.height) + if (!hasSentSound) { + SoundUtils.playErrorSound() + hasSentSound = true + } + } + + private fun sendTitle(width: Int, height: Int) { + GlStateManager.pushMatrix() + GlStateManager.translate(0f, -150f, 500f) + + Renderable.drawInsideRoundedRect( + Renderable.string("§dMissing Guardian Pet", 1.5), + Color(Color.DARK_GRAY.withAlpha(0), true), + horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, + verticalAlign = RenderUtils.VerticalAlignment.CENTER, + ).renderXYAligned(0, 125, width, height) + + GlStateManager.translate(0f, 150f, -500f) + GlStateManager.popMatrix() + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.guardianReminder +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/UltraRareBookAlert.kt similarity index 98% rename from src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt rename to src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/UltraRareBookAlert.kt index 32f6ebb7e888..1cc849cad60a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/UltraRareBookAlert.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.inventory +package at.hannibal2.skyhanni.features.inventory.experiments import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiRenderEvent From b11cf9178f1ae56cb6f312dd0b2421f0a3865908 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:26:46 +0200 Subject: [PATCH 2/2] code cleanup, added clickable chat message --- .../inventory/helper/HelperConfig.java | 2 +- .../inventory/experiments/GuardianReminder.kt | 37 +++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java index ec67cda88931..5f54e707d010 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/helper/HelperConfig.java @@ -76,7 +76,7 @@ public static class EnchantingConfig { public boolean ultraRareBookAlert = false; @Expose - @ConfigOption(name = "Guardian Reminder", desc = "Sends a warning when opening the experimentation table") + @ConfigOption(name = "Guardian Reminder", desc = "Sends a warning when opening the Experimentation Table without a §9§lGuardian Pet §7equipped.") @ConfigEditorBoolean @FeatureToggle public boolean guardianReminder = false; diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt index d55f4e364703..20c0438c91ce 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt @@ -3,10 +3,11 @@ package at.hannibal2.skyhanni.features.inventory.experiments import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha +import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.matches @@ -21,14 +22,15 @@ import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.client.renderer.GlStateManager import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @SkyHanniModule object GuardianReminder { private val config get() = SkyHanniMod.feature.inventory.helper.enchanting - private var lastNotificationTime = SimpleTimeMark.farPast() - private var hasSentSound = false + private var lastInventoryOpen = SimpleTimeMark.farPast() + private var lastErrorSound = SimpleTimeMark.farPast() private val patternGroup = RepoPattern.group("data.enchanting.inventory.experimentstable") private val inventoryNamePattern by patternGroup.pattern( @@ -37,7 +39,7 @@ object GuardianReminder { ) private val petNamePattern by patternGroup.pattern( "guardianpet", - "§[56d]Guardian", + "§[956d]Guardian", ) @SubscribeEvent @@ -46,34 +48,37 @@ object GuardianReminder { if (!inventoryNamePattern.matches(event.inventoryName)) return if (petNamePattern.matches(PetAPI.currentPet)) return - lastNotificationTime = SimpleTimeMark.now() - } - - @SubscribeEvent - fun onInventoryClose(event: InventoryCloseEvent) { - if (hasSentSound) hasSentSound = false + lastInventoryOpen = SimpleTimeMark.now() + ChatUtils.clickToActionOrDisable( + "Use a §9§lGuardian Pet §efor more Exp in the Experimentation Table.", + option = config::guardianReminder, + actionName = "open pets menu", + action = { + HypixelCommands.pet() + }, + ) } @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { if (!isEnabled()) return if (!inventoryNamePattern.matches(InventoryUtils.openInventoryName())) return - if (lastNotificationTime.passedSince() > 2.seconds) return + if (lastInventoryOpen.passedSince() > 2.seconds) return val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return sendTitle(gui.width, gui.height) - if (!hasSentSound) { - SoundUtils.playErrorSound() - hasSentSound = true + if (lastErrorSound.passedSince() > 200.milliseconds) { + lastErrorSound = SimpleTimeMark.now() + SoundUtils.playPlingSound() } } + // TODO rename to "send title in inventory", move to utils private fun sendTitle(width: Int, height: Int) { GlStateManager.pushMatrix() GlStateManager.translate(0f, -150f, 500f) - Renderable.drawInsideRoundedRect( - Renderable.string("§dMissing Guardian Pet", 1.5), + Renderable.string("§cWrong Pet equipped!", 1.5), Color(Color.DARK_GRAY.withAlpha(0), true), horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, verticalAlign = RenderUtils.VerticalAlignment.CENTER,