-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Rabbit the Fish GUI Close Blocker (#2712)
Co-authored-by: hannibal2 <[email protected]>
- Loading branch information
1 parent
068e021
commit e2f7293
Showing
7 changed files
with
140 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/at/hannibal2/skyhanni/config/features/event/hoppity/HoppityWarpMenuConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityRabbitTheFishChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters