diff options
| author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-06-16 17:31:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-16 17:31:50 +0200 |
| commit | e9ea84e533f5db928a47850e87000f63bad49c45 (patch) | |
| tree | 332596fc17517a97b38d3d263d5b08dba385c4e5 /src/main/java/at/hannibal2/skyhanni/features | |
| parent | 37bb14382e8aac7798de1e567b8e9410727ef5fd (diff) | |
| download | skyhanni-e9ea84e533f5db928a47850e87000f63bad49c45.tar.gz skyhanni-e9ea84e533f5db928a47850e87000f63bad49c45.tar.bz2 skyhanni-e9ea84e533f5db928a47850e87000f63bad49c45.zip | |
Improvement: Add Keybinds to Custom Wardrobe (#2105)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
3 files changed, 56 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt index ff9a7610a..1c3f36aeb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobe.kt @@ -111,8 +111,7 @@ object CustomWardrobe { @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { waitingForInventoryUpdate = false - if (!isEnabled()) return - DelayedRun.runDelayed(250.milliseconds) { + DelayedRun.runDelayed(300.milliseconds) { if (!WardrobeAPI.inWardrobe()) { reset() } @@ -587,7 +586,7 @@ object CustomWardrobe { } } - private fun WardrobeSlot.clickSlot() { + fun WardrobeSlot.clickSlot() { val previousPageSlot = 45 val nextPageSlot = 53 val wardrobePage = WardrobeAPI.currentPage ?: return 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 new file mode 100644 index 000000000..2e3716cb2 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/CustomWardrobeKeybinds.kt @@ -0,0 +1,53 @@ +package at.hannibal2.skyhanni.features.inventory.wardrobe + +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.LorenzUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.milliseconds + +@SkyHanniModule +object CustomWardrobeKeybinds { + + private val config get() = SkyHanniMod.feature.inventory.customWardrobe + private val keybinds + get() = listOf( + config.keybinds.slot1, + config.keybinds.slot2, + config.keybinds.slot3, + config.keybinds.slot4, + config.keybinds.slot5, + config.keybinds.slot6, + config.keybinds.slot7, + config.keybinds.slot8, + config.keybinds.slot9, + ) + var lastClick = SimpleTimeMark.farPast() + + @SubscribeEvent + fun onGui(event: GuiKeyPressEvent) { + if (!isEnabled()) return + val slots = WardrobeAPI.slots.filter { it.isInCurrentPage() } + + for ((key, index) in keybinds.withIndex().map { it.value to it.index }) { + if (!key.isKeyClicked()) continue + if (lastClick.passedSince() < 200.milliseconds) break + val slot = slots.getOrNull(index) ?: continue + + event.cancel() + + slot.clickSlot() + lastClick = SimpleTimeMark.now() + break + } + } + + fun allowKeyboardClick() = isEnabled() && keybinds.any { it.isKeyClicked() } + + private fun isEnabled() = LorenzUtils.inSkyBlock && WardrobeAPI.inCustomWardrobe && config.keybinds.slotKeybindsToggle && config.enabled + +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/WardrobeAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/WardrobeAPI.kt index b49ba106a..f57761102 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/WardrobeAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/wardrobe/WardrobeAPI.kt @@ -44,7 +44,7 @@ object WardrobeAPI { "§7Slot \\d+: §aEquipped", ) - private const val FIRST_SLOT = 36 + const val FIRST_SLOT = 36 private const val FIRST_HELMET_SLOT = 0 private const val FIRST_CHESTPLATE_SLOT = 9 private const val FIRST_LEGGINGS_SLOT = 18 |
