From e7a4ba8bee43ccdcaee5192f4d2a0034db9f488f Mon Sep 17 00:00:00 2001 From: martimavocado <39881008+martimavocado@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:27:24 +0100 Subject: Feature: Experimentation Table Guardian warning (#2127) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/inventory/UltraRareBookAlert.kt | 104 --------------------- .../inventory/experiments/GuardianReminder.kt | 92 ++++++++++++++++++ .../inventory/experiments/UltraRareBookAlert.kt | 104 +++++++++++++++++++++ 3 files changed, 196 insertions(+), 104 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/UltraRareBookAlert.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt deleted file mode 100644 index 32f6ebb7e..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/UltraRareBookAlert.kt +++ /dev/null @@ -1,104 +0,0 @@ -package at.hannibal2.skyhanni.features.inventory - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.InventoryCloseEvent -import at.hannibal2.skyhanni.events.InventoryUpdatedEvent -import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.utils.ChatUtils -import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher -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.createSound -import at.hannibal2.skyhanni.utils.SoundUtils.playSound -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 UltraRareBookAlert { - - private val config get() = SkyHanniMod.feature.inventory.helper.enchanting - private val dragonSound by lazy { createSound("mob.enderdragon.growl", 1f) } - - private val patternGroup = RepoPattern.group("data.enchanting") - private val superpairsGui by patternGroup.pattern( - "inventory.experimentstable.gui", - "Superpairs.*" - ) - private val ultraRarePattern by patternGroup.pattern( - "inventory.experimentstable.ultrarare", - "§d§kXX§5 ULTRA-RARE BOOK! §d§kXX" - ) - private val bookPattern by patternGroup.pattern( - "inventory.experimentstable.book", - "§9(?.*)" - ) - - private var enchantsFound = false - - private var lastNotificationTime = SimpleTimeMark.farPast() - - private fun notification(enchantsName: String) { - lastNotificationTime = SimpleTimeMark.now() - dragonSound.playSound() - ChatUtils.chat("You have uncovered a §d§kXX§5 ULTRA-RARE BOOK! §d§kXX§e! You found: §9$enchantsName") - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!config.ultraRareBookAlert) return - if (!superpairsGui.matches(InventoryUtils.openInventoryName())) return - if (lastNotificationTime.passedSince() > 5.seconds) return - val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return - - GlStateManager.pushMatrix() - GlStateManager.translate(0f, -150f, 500f) - - Renderable.drawInsideRoundedRect( - Renderable.string("§d§kXX§5 ULTRA-RARE BOOK! §d§kXX", 1.5), - Color(Color.DARK_GRAY.withAlpha(0), true), - horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, - verticalAlign = RenderUtils.VerticalAlignment.CENTER, - ).renderXYAligned(0, 125, gui.width, gui.height) - - GlStateManager.translate(0f, 150f, -500f) - GlStateManager.popMatrix() - } - - @SubscribeEvent - fun onInventoryUpdated(event: InventoryUpdatedEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!config.ultraRareBookAlert) return - if (enchantsFound) return - if (!superpairsGui.matches(event.inventoryName)) return - - for (lore in event.inventoryItems.map { it.value.getLore() }) { - val firstLine = lore.firstOrNull() ?: continue - if (!ultraRarePattern.matches(firstLine)) continue - val bookNameLine = lore.getOrNull(2) ?: continue - bookPattern.matchMatcher(bookNameLine) { - val enchantsName = group("enchant") - notification(enchantsName) - enchantsFound = true - } - } - } - - @SubscribeEvent - fun onInventoryClose(event: InventoryCloseEvent) { - enchantsFound = 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 000000000..20c0438c9 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/GuardianReminder.kt @@ -0,0 +1,92 @@ +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.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 +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.milliseconds +import kotlin.time.Duration.Companion.seconds + +@SkyHanniModule +object GuardianReminder { + + private val config get() = SkyHanniMod.feature.inventory.helper.enchanting + 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( + "mainmenu", + "Experimentation Table", + ) + private val petNamePattern by patternGroup.pattern( + "guardianpet", + "§[956d]Guardian", + ) + + @SubscribeEvent + fun onInventory(event: InventoryFullyOpenedEvent) { + if (!isEnabled()) return + if (!inventoryNamePattern.matches(event.inventoryName)) return + if (petNamePattern.matches(PetAPI.currentPet)) return + + 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 (lastInventoryOpen.passedSince() > 2.seconds) return + val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return + + sendTitle(gui.width, gui.height) + 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("§cWrong Pet equipped!", 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/experiments/UltraRareBookAlert.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/UltraRareBookAlert.kt new file mode 100644 index 000000000..1cc849cad --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experiments/UltraRareBookAlert.kt @@ -0,0 +1,104 @@ +package at.hannibal2.skyhanni.features.inventory.experiments + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +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.createSound +import at.hannibal2.skyhanni.utils.SoundUtils.playSound +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 UltraRareBookAlert { + + private val config get() = SkyHanniMod.feature.inventory.helper.enchanting + private val dragonSound by lazy { createSound("mob.enderdragon.growl", 1f) } + + private val patternGroup = RepoPattern.group("data.enchanting") + private val superpairsGui by patternGroup.pattern( + "inventory.experimentstable.gui", + "Superpairs.*" + ) + private val ultraRarePattern by patternGroup.pattern( + "inventory.experimentstable.ultrarare", + "§d§kXX§5 ULTRA-RARE BOOK! §d§kXX" + ) + private val bookPattern by patternGroup.pattern( + "inventory.experimentstable.book", + "§9(?.*)" + ) + + private var enchantsFound = false + + private var lastNotificationTime = SimpleTimeMark.farPast() + + private fun notification(enchantsName: String) { + lastNotificationTime = SimpleTimeMark.now() + dragonSound.playSound() + ChatUtils.chat("You have uncovered a §d§kXX§5 ULTRA-RARE BOOK! §d§kXX§e! You found: §9$enchantsName") + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.ultraRareBookAlert) return + if (!superpairsGui.matches(InventoryUtils.openInventoryName())) return + if (lastNotificationTime.passedSince() > 5.seconds) return + val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return + + GlStateManager.pushMatrix() + GlStateManager.translate(0f, -150f, 500f) + + Renderable.drawInsideRoundedRect( + Renderable.string("§d§kXX§5 ULTRA-RARE BOOK! §d§kXX", 1.5), + Color(Color.DARK_GRAY.withAlpha(0), true), + horizontalAlign = RenderUtils.HorizontalAlignment.CENTER, + verticalAlign = RenderUtils.VerticalAlignment.CENTER, + ).renderXYAligned(0, 125, gui.width, gui.height) + + GlStateManager.translate(0f, 150f, -500f) + GlStateManager.popMatrix() + } + + @SubscribeEvent + fun onInventoryUpdated(event: InventoryUpdatedEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.ultraRareBookAlert) return + if (enchantsFound) return + if (!superpairsGui.matches(event.inventoryName)) return + + for (lore in event.inventoryItems.map { it.value.getLore() }) { + val firstLine = lore.firstOrNull() ?: continue + if (!ultraRarePattern.matches(firstLine)) continue + val bookNameLine = lore.getOrNull(2) ?: continue + bookPattern.matchMatcher(bookNameLine) { + val enchantsName = group("enchant") + notification(enchantsName) + enchantsFound = true + } + } + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + enchantsFound = false + } +} -- cgit