diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index f6d6c72de14d..8228ae025274 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, 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 3fd83db69655..f34959bd8a97 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 @@ -24,6 +24,11 @@ public class HoppityEggsConfig { @Accordion 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 @@ -213,13 +218,8 @@ public String toString() { 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 000000000000..680b2918e876 --- /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 a69366931886..4b3451514839 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 000000000000..50608954ae67 --- /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 { + + // + /** + * 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!", + ) + // + + 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 939dea1b702f..dfd22de9a88f 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>? 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 0c58469cd12e..071d399adc91 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 @@ private void closeWindowPressed(CallbackInfo ci) { 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);