From db0cd17c7019c072a5043ae8d0dca8ce6459fb32 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Thu, 12 Oct 2023 22:31:49 +1100 Subject: Fix + Backend: Made mouse buttons work as key binds (#560) Fix + Backend: Made mouse buttons work as key binds #560 --- .../features/event/diana/BurrowWarpHelper.kt | 29 ++++++++++------------ .../event/diana/InquisitorWaypointShare.kt | 11 +++----- 2 files changed, 16 insertions(+), 24 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/event') diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt index f96c6d260..afbf7e16b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt @@ -3,34 +3,33 @@ package at.hannibal2.skyhanni.features.event.diana import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.sorted import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent -import org.lwjgl.input.Keyboard +import kotlin.time.Duration.Companion.seconds class BurrowWarpHelper { - private var lastWarpTime = 0L + private var lastWarpTime = SimpleTimeMark.farPast() private var lastWarp: WarpPoint? = null @SubscribeEvent - fun onKeyBindPressed(event: KeyInputEvent) { + fun onKeyClick(event: LorenzKeyPressEvent) { if (!LorenzUtils.inSkyBlock) return if (LorenzUtils.skyBlockIsland != IslandType.HUB) return if (!config.burrowNearestWarp) return - if (!Keyboard.getEventKeyState()) return - val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() - if (config.keyBindWarp == key) { - currentWarp?.let { - if (System.currentTimeMillis() > lastWarpTime + 5_000) { - lastWarpTime = System.currentTimeMillis() - LorenzUtils.sendCommandToServer("warp " + currentWarp?.name) - lastWarp = currentWarp - } + if (event.keyCode != config.keyBindWarp) return + + currentWarp?.let { + if (lastWarpTime.passedSince() < 5.seconds) { + lastWarpTime = SimpleTimeMark.now() + LorenzUtils.sendCommandToServer("warp " + currentWarp?.name) + lastWarp = currentWarp } } } @@ -40,8 +39,7 @@ class BurrowWarpHelper { if (!LorenzUtils.inSkyBlock) return if (event.message == "§cYou haven't unlocked this fast travel destination!") { - val time = System.currentTimeMillis() - lastWarpTime - if (time < 1_000) { + if (lastWarpTime.passedSince() < 1.seconds) { lastWarp?.let { it.unlocked = false LorenzUtils.chat( @@ -53,7 +51,6 @@ class BurrowWarpHelper { } } } - } companion object { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt index 8c139c923..caf2cb014 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.PacketEvent @@ -25,8 +26,6 @@ import net.minecraft.network.play.server.S02PacketChat import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.InputEvent -import org.lwjgl.input.Keyboard import kotlin.time.Duration.Companion.seconds object InquisitorWaypointShare { @@ -164,13 +163,9 @@ object InquisitorWaypointShare { } @SubscribeEvent - fun onKeyBindPressed(event: InputEvent.KeyInputEvent) { + fun onKeyClick(event: LorenzKeyPressEvent) { if (!isEnabled()) return - if (!Keyboard.getEventKeyState()) return - val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() - if (config.keyBindShare == key) { - sendInquisitor() - } + if (event.keyCode == config.keyBindShare) sendInquisitor() } private fun sendDeath() { -- cgit