Skip to content

Commit

Permalink
Feature: Rabbit the Fish GUI Close Blocker (#2712)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
DavidArthurCole and hannibal002 authored Oct 16, 2024
1 parent 068e021 commit e2f7293
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) &&
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit e2f7293

Please sign in to comment.