1717
1818package com.lambda.module.modules.player
1919
20- import com.lambda.event.events.MovementEvent
21- import com.lambda.event.events.UpdateManagerEvent
22- import com.lambda.event.listener.SafeListener.Companion.listen
20+ import com.lambda.Lambda.mc
2321import com.lambda.gui.LambdaScreen
2422import com.lambda.interaction.request.rotating.Rotation
2523import com.lambda.interaction.request.rotating.RotationConfig
24+ import com.lambda.interaction.request.rotating.RotationManager.onRotate
2625import com.lambda.interaction.request.rotating.RotationMode
2726import com.lambda.interaction.request.rotating.visibilty.lookAt
2827import com.lambda.module.Module
2928import com.lambda.module.tag.ModuleTag
3029import com.lambda.util.KeyboardUtils.isKeyPressed
31- import com.lambda.util.math.MathUtils.toDouble
3230import com.lambda.util.math.MathUtils.toFloatSign
33- import com.lambda.util.player.MovementUtils.update
3431import net.minecraft.client.gui.screen.ChatScreen
3532import net.minecraft.client.gui.screen.Screen
33+ import net.minecraft.client.gui.screen.ingame.AbstractCommandBlockScreen
34+ import net.minecraft.client.gui.screen.ingame.AbstractSignEditScreen
3635import net.minecraft.client.gui.screen.ingame.AnvilScreen
37- import net.minecraft.client.gui.screen.ingame.CommandBlockScreen
38- import net.minecraft.client.gui.screen.ingame.SignEditScreen
39- import org.lwjgl.glfw.GLFW.GLFW_KEY_A
40- import org.lwjgl.glfw.GLFW.GLFW_KEY_D
4136import org.lwjgl.glfw.GLFW.GLFW_KEY_DOWN
4237import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_2
4338import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_4
4439import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_6
4540import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_8
4641import org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT
47- import org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL
48- import org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_SHIFT
4942import org.lwjgl.glfw.GLFW.GLFW_KEY_RIGHT
50- import org.lwjgl.glfw.GLFW.GLFW_KEY_S
51- import org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE
5243import org.lwjgl.glfw.GLFW.GLFW_KEY_UP
53- import org.lwjgl.glfw.GLFW.GLFW_KEY_W
5444
5545object InventoryMove : Module(
5646 name = " InventoryMove" ,
5747 description = " Allows you to move with GUIs opened" ,
5848 tag = ModuleTag .PLAYER ,
5949) {
60- private val speed by setting(" Rotation Speed" , 5 , 1 .. 20 , 1 , unit = " °/tick" )
50+ private val arrowKeys by setting(" Arrow Keys" , false , " Allows rotating the players camera using the arrow keys" )
51+ private val speed by setting(" Rotation Speed" , 5 , 1 .. 20 , 1 , unit = " °/tick" ) { arrowKeys }
6152 private val rotationConfig = RotationConfig .Instant (RotationMode .Lock )
6253
54+ @JvmStatic
55+ val shouldMove get() = isEnabled && ! mc.currentScreen.hasInputOrNull
56+
6357 /* *
6458 * Whether the current screen has text inputs or is null
6559 */
60+ @JvmStatic
6661 val Screen ?.hasInputOrNull: Boolean
6762 get() = this is ChatScreen ||
68- this is SignEditScreen ||
63+ this is AbstractSignEditScreen ||
6964 this is AnvilScreen ||
70- this is CommandBlockScreen ||
65+ this is AbstractCommandBlockScreen ||
7166 this is LambdaScreen ||
7267 this == null
7368
7469 init {
75- listen<MovementEvent .InputUpdate >(20250415 ) { event ->
76- if (mc.currentScreen.hasInputOrNull) return @listen
77-
78- val forward = isKeyPressed(GLFW_KEY_W ).toDouble() -
79- isKeyPressed(GLFW_KEY_S ).toDouble()
80-
81- val strafe = isKeyPressed(GLFW_KEY_A ).toDouble() -
82- isKeyPressed(GLFW_KEY_D ).toDouble()
83-
84- val jump = isKeyPressed(GLFW_KEY_SPACE )
85- val sneak = isKeyPressed(GLFW_KEY_LEFT_SHIFT )
86- val sprint = isKeyPressed(GLFW_KEY_LEFT_CONTROL )
87-
88- event.input.update(forward, strafe, jump, sneak, sprint)
89- }
90-
91- listen<UpdateManagerEvent .Rotation > {
92- if (mc.currentScreen.hasInputOrNull) return @listen
70+ onRotate {
71+ if (! arrowKeys || mc.currentScreen.hasInputOrNull) return @onRotate
9372
9473 val pitch = (isKeyPressed(GLFW_KEY_DOWN , GLFW_KEY_KP_2 ).toFloatSign() -
9574 isKeyPressed(GLFW_KEY_UP , GLFW_KEY_KP_8 ).toFloatSign()) * speed
@@ -101,4 +80,19 @@ object InventoryMove : Module(
10180 ).requestBy(rotationConfig)
10281 }
10382 }
83+
84+ @JvmStatic
85+ fun isKeyMovementRelated (key : Int ): Boolean {
86+ val options = mc.options
87+ return when (key) {
88+ options.forwardKey.boundKey.code,
89+ options.backKey.boundKey.code,
90+ options.leftKey.boundKey.code,
91+ options.rightKey.boundKey.code,
92+ options.jumpKey.boundKey.code,
93+ options.sprintKey.boundKey.code,
94+ options.sneakKey.boundKey.code -> true
95+ else -> false
96+ }
97+ }
10498}
0 commit comments