diff options
author | David Cole <40234707+DavidArthurCole@users.noreply.github.com> | 2024-10-16 13:47:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-16 19:47:41 +0200 |
commit | e2f7293cae6c76b31ad77f59380a688fcdcacde2 (patch) | |
tree | 49a7536b169f28ca5b72d067037a1d82a16e0111 | |
parent | 068e021a288d0b0a2e9e1947dbefec3bd619db1e (diff) | |
download | skyhanni-e2f7293cae6c76b31ad77f59380a688fcdcacde2.tar.gz skyhanni-e2f7293cae6c76b31ad77f59380a688fcdcacde2.tar.bz2 skyhanni-e2f7293cae6c76b31ad77f59380a688fcdcacde2.zip |
Feature: Rabbit the Fish GUI Close Blocker (#2712)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
7 files changed, 140 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index f6d6c72de..8228ae025 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 61 + const val CONFIG_VERSION = 62 fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityEggsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityEggsConfig.java index 3fd83db69..f34959bd8 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityEggsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityEggsConfig.java @@ -25,6 +25,11 @@ public class HoppityEggsConfig { public HoppityEventSummaryConfig eventSummary = new HoppityEventSummaryConfig(); @Expose + @ConfigOption(name = "Warp Menu", desc = "") + @Accordion + public HoppityWarpMenuConfig warpMenu = new HoppityWarpMenuConfig(); + + @Expose @ConfigOption(name = "Hoppity Waypoints", desc = "Toggle guess waypoints for Hoppity's Hunt.") @ConfigEditorBoolean @FeatureToggle @@ -213,13 +218,8 @@ public class HoppityEggsConfig { public boolean petWarning = false; @Expose - @ConfigOption(name = "Show uniques in Warp Menu", desc = "Shows your unique eggs in the Warp Menu during the hoppity event.") + @ConfigOption(name = "Prevent Missing Fish the Rabbit", desc = "Prevent closing a Meal Egg's inventory if Fish the Rabbit is present.") @ConfigEditorBoolean @FeatureToggle - public boolean uniquesWarpMenu = true; - - @Expose - @ConfigOption(name = "Hide when maxed", desc = "Stops the above feature from working when the island is complete.") - @ConfigEditorBoolean - public boolean uniquesWarpMenuHideMax = true; + public boolean preventMissingFish = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityWarpMenuConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityWarpMenuConfig.java new file mode 100644 index 000000000..680b2918e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityWarpMenuConfig.java @@ -0,0 +1,20 @@ +package at.hannibal2.skyhanni.config.features.event.hoppity; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class HoppityWarpMenuConfig { + + @Expose + @ConfigOption(name = "Show uniques in Warp Menu", desc = "Shows your unique eggs in the Warp Menu during the hoppity event.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Hide when maxed", desc = "Stops the above feature from working when the island is complete.") + @ConfigEditorBoolean + public boolean hideWhenMaxed = true; +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt index a69366931..4b3451514 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggsManager.kt @@ -259,6 +259,8 @@ object HoppityEggsManager { ) event.move(44, "event.chocolateFactory.hoppityEggs", "event.hoppityEggs") event.move(50, "event.hoppityEggs.showDuringContest", "event.hoppityEggs.showWhileBusy") + event.move(62, "event.hoppityEggs.uniquesWarpMenu", "event.hoppityEggs.warpMenu.enabled") + event.move(62, "event.hoppityEggs.uniquesWarpMenuHideMax", "event.hoppityEggs.warpMenu.hideWhenMaxed") } fun isActive() = (LorenzUtils.inSkyBlock || (LorenzUtils.onHypixel && config.showOutsideSkyblock)) && diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityRabbitTheFishChecker.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityRabbitTheFishChecker.kt new file mode 100644 index 000000000..50608954a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityRabbitTheFishChecker.kt @@ -0,0 +1,99 @@ +package at.hannibal2.skyhanni.features.event.hoppity + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RegexUtils.anyMatches +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import at.hannibal2.skyhanni.utils.SoundUtils +import net.minecraft.client.Minecraft +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Keyboard + +@SkyHanniModule +object HoppityRabbitTheFishChecker { + + //<editor-fold desc="Patterns"> + /** + * REGEX-TEST: Chocolate Breakfast Egg + * REGEX-TEST: Chocolate Lunch Egg + * REGEX-TEST: Chocolate Dinner Egg + */ + private val mealEggInventoryPattern by ChocolateFactoryAPI.patternGroup.pattern( + "inventory.mealegg.name", + "(?:§.)*Chocolate (?:Breakfast|Lunch|Dinner) Egg.*", + ) + + /** + * REGEX-TEST: §cRabbit the Fish + */ + private val rabbitTheFishItemPattern by ChocolateFactoryAPI.patternGroup.pattern( + "item.rabbitthefish", + "(?:§.)*Rabbit the Fish", + ) + + /** + * REGEX-TEST: Click to open Chocolate Factory! + */ + private val openCfSlotLorePattern by ChocolateFactoryAPI.patternGroup.pattern( + "inventory.mealegg.continue", + "(?:§.)*Click to open Chocolate Factory!", + ) + //</editor-fold> + + private val config get() = SkyHanniMod.feature.event.hoppityEggs + private var rabbitTheFishIndex: Int? = null + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!isEnabled()) return + + rabbitTheFishIndex?.let { + InventoryUtils.getItemsInOpenChest()[it] highlight LorenzColor.RED + } + } + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + if (!isEnabled() || !mealEggInventoryPattern.matches(event.inventoryName)) return + + rabbitTheFishIndex = event.inventoryItems.filter { + it.value.hasDisplayName() + }.entries.firstOrNull { + rabbitTheFishItemPattern.matches(it.value.displayName) + }?.key + } + + @SubscribeEvent + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!isEnabled() || rabbitTheFishIndex == null) return + + // Prevent opening chocolate factory when Rabbit the Fish is present + val stack = event.slot?.stack ?: return + if (openCfSlotLorePattern.anyMatches(stack.getLore())) { + event.cancel() + SoundUtils.playErrorSound() + } else if (rabbitTheFishIndex == event.slot.slotNumber) { + rabbitTheFishIndex = null + } + } + + private fun Int.isInventoryClosure(): Boolean = + this == Minecraft.getMinecraft().gameSettings.keyBindInventory.keyCode || this == Keyboard.KEY_ESCAPE + + @JvmStatic + fun shouldContinueWithKeypress(keycode: Int): Boolean { + val shouldContinue = !keycode.isInventoryClosure() || !isEnabled() || rabbitTheFishIndex == null + if (!shouldContinue) SoundUtils.playErrorSound() + return shouldContinue + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && HoppityAPI.isHoppityEvent() && config.preventMissingFish +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/WarpMenuUniques.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/WarpMenuUniques.kt index 939dea1b7..dfd22de9a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/WarpMenuUniques.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/WarpMenuUniques.kt @@ -27,12 +27,12 @@ object WarpMenuUniques { private val collectedEggStorage: MutableMap<IslandType, MutableSet<LorenzVec>>? get() = ChocolateFactoryAPI.profileStorage?.collectedEggLocations - private val config get() = SkyHanniMod.feature.event.hoppityEggs + private val config get() = SkyHanniMod.feature.event.hoppityEggs.warpMenu @SubscribeEvent fun onTooltip(event: LorenzToolTipEvent) { if (!LorenzUtils.inSkyBlock) return - if (!config.uniquesWarpMenu) return + if (!config.enabled) return if (!HoppityAPI.isHoppityEvent()) return if (event.slot.inventory.name != "Fast Travel") return @@ -51,7 +51,7 @@ object WarpMenuUniques { val maxEggs = 15 val collectedEggs = collectedEggStorage?.get(island)?.size ?: 0 - if (collectedEggs >= maxEggs && config.uniquesWarpMenuHideMax) return + if (collectedEggs >= maxEggs && config.hideWhenMaxed) return event.toolTip.add(2, "§7Collected Hoppity Eggs: ${if (collectedEggs == maxEggs) "§a" else ""}$collectedEggs/$maxEggs") } diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java index 0c58469cd..071d399ad 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.mixins.transformers.gui; import at.hannibal2.skyhanni.data.ToolTipData; +import at.hannibal2.skyhanni.features.event.hoppity.HoppityRabbitTheFishChecker; import at.hannibal2.skyhanni.mixins.hooks.GuiContainerHook; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; @@ -26,6 +27,13 @@ public abstract class MixinGuiContainer extends GuiScreen { skyHanni$hook.closeWindowPressed(ci); } + @Inject(method = "keyTyped", at = @At("HEAD"), cancellable = true) + private void onKeyTyped(char typedChar, int keyCode, CallbackInfo ci) { + if (!HoppityRabbitTheFishChecker.shouldContinueWithKeypress(keyCode)) { + ci.cancel(); + } + } + @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFFF)V", ordinal = 1)) private void backgroundDrawn(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { skyHanni$hook.backgroundDrawn(mouseX, mouseY, partialTicks); |