From 8bcdd9b6de9f7fc53cfed31ab84187092ea4dc6e Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:54:52 +0200 Subject: Feature: Scrolling pages (#2164) --- .../skyhanni/features/inventory/PageScrolling.kt | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt new file mode 100644 index 000000000..f9855d0d4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt @@ -0,0 +1,75 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ToolTipData +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow +import at.hannibal2.skyhanni.utils.renderables.ScrollValue +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Mouse +import kotlin.time.Duration.Companion.seconds + +@SkyHanniModule +object PageScrolling { + + private val config get() = SkyHanniMod.feature.inventory.pageScrolling + + private val repoGroup = RepoPattern.group("inventory.pagescrolling") + + private val illegalInventory by repoGroup.list( + "illegal", + "Large Chest", + "Chest", + ) + + private val forwardPattern by repoGroup.list( + "forward", + "§aNext Page", + "§aScroll Up", + "§aLevels 26 - 50", + "§aNext Page →", + ) + + private val backwardPattern by repoGroup.list( + "backward", + "§aPrevious Page", + "§aScroll Down", + "§aLevels 1 - 25", + "§a← Previous Page", + ) + + private val scroll = ScrollValue() + + private var cooldown = SimpleTimeMark.farPast() + + @SubscribeEvent + fun onLorenzTick(event: LorenzTickEvent) { + if (!isEnabled()) return + if (cooldown.isInFuture()) return + if (!scroll.isMouseEventValid()) return + + val inventoryName = InventoryUtils.openInventoryName() + if (inventoryName.isEmpty()) return + if (illegalInventory.matches(inventoryName)) return + + if (((ToolTipData.lastSlot != null) xor config.invertBypass xor config.bypassKey.isKeyHeld())) return + + val dWheel = Mouse.getEventDWheel() + if (dWheel == 0) return + val patterns = if ((dWheel > 0) xor config.invertScroll) forwardPattern else backwardPattern + val slot = InventoryUtils.getItemsInOpenChest().firstOrNull { + patterns.matches(it.stack?.displayName) + } ?: return + InventoryUtils.clickSlot(slot.slotNumber) + cooldown = 1.0.seconds.fromNow() // 1 second is not specific it is just a reasonable cooldown + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.enable && InventoryUtils.inInventory() +} -- cgit