diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-03 20:28:51 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-03 20:28:51 +0100 |
commit | 3d1b6f71080f2cfc48a36db8880da64073f023bb (patch) | |
tree | 8a4c5c96e3f26e6ad2505e597f6bbbff1b0a9673 /src/main/java/at/hannibal2 | |
parent | b3426297169836aceee7486bab89035c35c6d126 (diff) | |
download | skyhanni-3d1b6f71080f2cfc48a36db8880da64073f023bb.tar.gz skyhanni-3d1b6f71080f2cfc48a36db8880da64073f023bb.tar.bz2 skyhanni-3d1b6f71080f2cfc48a36db8880da64073f023bb.zip |
code cleanup
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt index 3c0a40870..f2b17d79d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt @@ -19,31 +19,24 @@ object HarpFeatures { val config get() = SkyHanniMod.feature.inventory.helper.harp private var lastClick = SimpleTimeMark.farPast() - private object keys : - Iterable<Int> { - override fun iterator(): Iterator<Int> { - return object : Iterator<Int> { - private var currentIndex = 0 + private object KeyIterable : Iterable<Int> { + override fun iterator() = object : Iterator<Int> { + private var currentIndex = 0 - override fun hasNext(): Boolean { - return currentIndex < 7 - } + override fun hasNext() = currentIndex < 7 - override fun next(): Int { - return when (currentIndex++) { - 0 -> HarpFeatures.config.harpKeybinds.key1 - 1 -> HarpFeatures.config.harpKeybinds.key2 - 2 -> HarpFeatures.config.harpKeybinds.key3 - 3 -> HarpFeatures.config.harpKeybinds.key4 - 4 -> HarpFeatures.config.harpKeybinds.key5 - 5 -> HarpFeatures.config.harpKeybinds.key6 - 6 -> HarpFeatures.config.harpKeybinds.key7 - else -> throw NoSuchElementException() - } - } + override fun next() = when (currentIndex++) { + 0 -> config.harpKeybinds.key1 + 1 -> config.harpKeybinds.key2 + 2 -> config.harpKeybinds.key3 + 3 -> config.harpKeybinds.key4 + 4 -> config.harpKeybinds.key5 + 5 -> config.harpKeybinds.key6 + 6 -> config.harpKeybinds.key7 + + else -> throw NoSuchElementException("currentIndex: $currentIndex") } } - } private val buttonColors = listOf('d', 'e', 'a', '2', '5', '9', 'b') @@ -55,20 +48,19 @@ object HarpFeatures { if (!openInventoryName().startsWith("Harp")) return val chest = event.gui as? GuiChest ?: return - for ((index, key) in keys.withIndex()) { - if (key.isKeyHeld()) { - if (lastClick.passedSince() > 200.milliseconds) { - Minecraft.getMinecraft().playerController.windowClick( - chest.inventorySlots.windowId, - 37 + index, - 2, - 3, - Minecraft.getMinecraft().thePlayer - ) // middle clicks > left clicks - lastClick = SimpleTimeMark.now() - } - break - } + for ((index, key) in KeyIterable.withIndex()) { + if (!key.isKeyHeld()) continue + if (lastClick.passedSince() < 200.milliseconds) break + + Minecraft.getMinecraft().playerController.windowClick( + chest.inventorySlots.windowId, + 37 + index, + 2, + 3, + Minecraft.getMinecraft().thePlayer + ) // middle clicks > left clicks + lastClick = SimpleTimeMark.now() + break } } |