diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2023-05-09 06:53:45 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 22:53:45 +0200 |
commit | 55c2614cb69551363607cbdb7f42c38eccd3d38e (patch) | |
tree | 3e77f3ddca2a3a271d5a1f9d06f324111ab3d7ec /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 7a493ca560b74f1fe995fbe351c79eabaa90d432 (diff) | |
download | skyhanni-55c2614cb69551363607cbdb7f42c38eccd3d38e.tar.gz skyhanni-55c2614cb69551363607cbdb7f42c38eccd3d38e.tar.bz2 skyhanni-55c2614cb69551363607cbdb7f42c38eccd3d38e.zip |
Trevor features and solver (#92)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt index a96ccf62c..b920cdba6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt @@ -2,13 +2,15 @@ package at.hannibal2.skyhanni.features.garden.farming import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.features.Garden -import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.mixins.transformers.AccessorKeyBinding import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiEditSign import net.minecraft.client.settings.KeyBinding -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Keyboard +import org.lwjgl.input.Mouse import org.spongepowered.asm.mixin.injection.callback.CallbackInfo +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable import java.util.* object GardenCustomKeybinds { @@ -16,7 +18,7 @@ object GardenCustomKeybinds { private val mcSettings get() = Minecraft.getMinecraft().gameSettings private val map: MutableMap<KeyBinding, () -> Int> = IdentityHashMap() - private val cache: MutableMap<Int, Boolean> = mutableMapOf() + private var lastWindowOpenTime = 0L init { map[mcSettings.keyBindAttack] = { shConfig.keyBindAttack } @@ -31,35 +33,47 @@ object GardenCustomKeybinds { private fun isEnabled() = GardenAPI.inGarden() && shConfig.keyBindEnabled - private fun isActive() = isEnabled() && GardenAPI.toolInHand != null + private fun isActive(): Boolean { + if (!isEnabled()) return false + if (GardenAPI.toolInHand == null) return false - @SubscribeEvent - fun onToolChange(event: GardenToolChangeEvent) { - map.forEach { (keyBinding, override) -> - keyBinding as AccessorKeyBinding - val keyCode = if (isActive()) override() else keyBinding.keyCode - keyBinding.pressed_skyhanni = cache[keyCode] ?: false + if (Minecraft.getMinecraft().currentScreen != null) { + if (Minecraft.getMinecraft().currentScreen is GuiEditSign) { + lastWindowOpenTime = System.currentTimeMillis() + } + return false + } + + // TODO remove workaround + if (System.currentTimeMillis() < lastWindowOpenTime + 300) return false + + return true + } + + private fun isHeld(keyCode: Int): Boolean { + if (keyCode == 0) return false + return if (keyCode < 0) { + Mouse.isButtonDown(keyCode + 100) + } else { + Keyboard.isKeyDown(keyCode) } } @JvmStatic - fun onTick(keyCode: Int, ci: CallbackInfo) { - if (keyCode == 0) return + fun isKeyDown(keyBinding: KeyBinding, cir: CallbackInfoReturnable<Boolean>) { if (!isActive()) return - val keyBinding = map.entries.firstOrNull { it.value() == keyCode }?.key ?: return - ci.cancel() - keyBinding as AccessorKeyBinding - keyBinding.pressTime_skyhanni++ + val override = map[keyBinding] ?: return + val keyCode = override() + cir.returnValue = isHeld(keyCode) } @JvmStatic - fun setKeyBindState(keyCode: Int, pressed: Boolean, ci: CallbackInfo) { - if (keyCode == 0) return - cache[keyCode] = pressed + fun onTick(keyCode: Int, ci: CallbackInfo) { if (!isActive()) return + if (keyCode == 0) return val keyBinding = map.entries.firstOrNull { it.value() == keyCode }?.key ?: return ci.cancel() keyBinding as AccessorKeyBinding - keyBinding.pressed_skyhanni = pressed + keyBinding.pressTime_skyhanni++ } }
\ No newline at end of file |