diff options
author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-09-13 20:16:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-13 20:16:41 +0200 |
commit | 20081af74fd53f35746ab0d5c974bb5db92bec3b (patch) | |
tree | 8c297eb0a6fd36487e97b21eb1f34b2239ebb43a /src/main/java/at/hannibal2/skyhanni/features | |
parent | 326c632ed18b7677c72d86497e54086c9b409e9c (diff) | |
download | skyhanni-20081af74fd53f35746ab0d5c974bb5db92bec3b.tar.gz skyhanni-20081af74fd53f35746ab0d5c974bb5db92bec3b.tar.bz2 skyhanni-20081af74fd53f35746ab0d5c974bb5db92bec3b.zip |
Fix: Mouse Keys in Wardrobe (#2506)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobeKeybinds.kt | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobeKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobeKeybinds.kt index a2fdd21ff..b2ccdfe35 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobeKeybinds.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobeKeybinds.kt @@ -4,10 +4,10 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiKeyPressEvent import at.hannibal2.skyhanni.features.inventory.wardrobe.CustomWardrobe.clickSlot import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraftforge.client.event.GuiScreenEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds @@ -31,7 +31,16 @@ object CustomWardrobeKeybinds { @SubscribeEvent fun onGui(event: GuiKeyPressEvent) { - if (!isEnabled()) return + if (handlePress()) event.cancel() + } + + @SubscribeEvent + fun onMouse(event: GuiScreenEvent.MouseInputEvent.Pre) { + if (handlePress()) event.isCanceled = true + } + + private fun handlePress(): Boolean { + if (!isEnabled()) return false val slots = WardrobeAPI.slots.filter { it.isInCurrentPage() }.filterNot { config.onlyFavorites && !it.favorite } for ((index, key) in keybinds.withIndex()) { @@ -39,16 +48,16 @@ object CustomWardrobeKeybinds { if (lastClick.passedSince() < 200.milliseconds) break val slot = slots.getOrNull(index) ?: continue - event.cancel() - slot.clickSlot() lastClick = SimpleTimeMark.now() - break + return true } + + return false } - fun allowKeyboardClick() = isEnabled() && keybinds.any { it.isKeyClicked() } + fun allowMouseClick() = isEnabled() && keybinds.filter { it < 0 }.any { it.isKeyHeld() } + fun allowKeyboardClick() = isEnabled() && keybinds.filter { it > 0 }.any { it.isKeyHeld() } private fun isEnabled() = LorenzUtils.inSkyBlock && WardrobeAPI.inCustomWardrobe && config.keybinds.slotKeybindsToggle && config.enabled - } |