aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-06-30 11:54:52 +0200
committerGitHub <noreply@github.com>2024-06-30 11:54:52 +0200
commit8bcdd9b6de9f7fc53cfed31ab84187092ea4dc6e (patch)
tree0af5845280784c7053401258800f26c9bc9f189c /src/main/java/at/hannibal2/skyhanni/features
parent19606e3e9eda872c7f8036197213026d1326db45 (diff)
downloadskyhanni-8bcdd9b6de9f7fc53cfed31ab84187092ea4dc6e.tar.gz
skyhanni-8bcdd9b6de9f7fc53cfed31ab84187092ea4dc6e.tar.bz2
skyhanni-8bcdd9b6de9f7fc53cfed31ab84187092ea4dc6e.zip
Feature: Scrolling pages (#2164)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/PageScrolling.kt75
1 files changed, 75 insertions, 0 deletions
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()
+}