aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GuiData.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobeKeybinds.kt23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt13
3 files changed, 25 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
index 38ac99d1b..5f2ca510b 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
@@ -36,6 +36,9 @@ object GuiData {
@SubscribeEvent(priority = EventPriority.HIGH)
fun onGuiClick(event: GuiScreenEvent.MouseInputEvent.Pre) {
+
+ if (CustomWardrobeKeybinds.allowMouseClick()) return
+
if (preDrawEventCancelled) event.isCanceled = true
}
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
-
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
index dbdccb72a..f56ba4f0b 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
@@ -108,16 +108,15 @@ object KeyboardManager {
return this.isKeyDown || this.isPressed
}
- fun Int.isKeyHeld(): Boolean {
- if (this == 0) return false
- return if (this < 0) {
- Mouse.isButtonDown(this + 100)
- } else if (this >= Keyboard.KEYBOARD_SIZE) {
+ fun Int.isKeyHeld(): Boolean = when {
+ this == 0 -> false
+ this < 0 -> Mouse.isButtonDown(this + 100)
+ this >= Keyboard.KEYBOARD_SIZE -> {
val pressedKey = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey()
Keyboard.getEventKeyState() && this == pressedKey
- } else {
- Keyboard.isKeyDown(this)
}
+
+ else -> Keyboard.isKeyDown(this)
}
private val pressedKeys = mutableMapOf<Int, Boolean>()