Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidArthurCole committed Oct 16, 2024
1 parent 21ee982 commit 2b0d8b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.event.hoppity

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
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
Expand Down Expand Up @@ -61,11 +61,14 @@ object HoppityRabbitTheFishChecker {
}

@SubscribeEvent
fun onInventoryUpdate(event: InventoryUpdatedEvent) {
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
rabbitTheFishIndex = event.inventoryItems.filter {
it.value.hasDisplayName()
}.entries.firstOrNull {
rabbitTheFishItemPattern.matches(it.value.displayName)
}?.key
}

@SubscribeEvent
Expand All @@ -76,22 +79,20 @@ object HoppityRabbitTheFishChecker {
val stack = event.slot?.stack ?: return
if (openCfSlotLorePattern.anyMatches(stack.getLore())) {
event.cancel()
warn()
SoundUtils.playErrorSound()
} else if (rabbitTheFishIndex == event.slot.slotNumber) {
rabbitTheFishIndex = null
}
}

@JvmStatic
fun shouldContinueWithKeypress(keycode: Int) = !keycode.isInventoryClosure() || !isEnabled() || rabbitTheFishIndex == null

private fun Int.isInventoryClosure(): Boolean =
this == Minecraft.getMinecraft().gameSettings.keyBindInventory.keyCode || this == Keyboard.KEY_ESCAPE

@JvmStatic
fun warn() {
if (!isEnabled() || rabbitTheFishIndex == null) return
SoundUtils.playErrorSound()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ private void closeWindowPressed(CallbackInfo ci) {
private void onKeyTyped(char typedChar, int keyCode, CallbackInfo ci) {
if (!HoppityRabbitTheFishChecker.shouldContinueWithKeypress(keyCode)) {
ci.cancel();
HoppityRabbitTheFishChecker.warn();
}
}

Expand Down

0 comments on commit 2b0d8b0

Please sign in to comment.