Skip to content

Commit 8cad0d1

Browse files
committed
Rotation with arrow keys and numpad
1 parent 3ba8987 commit 8cad0d1

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

common/src/main/kotlin/com/lambda/module/modules/player/InventoryMove.kt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,34 @@ package com.lambda.module.modules.player
2020
import com.lambda.event.events.MovementEvent
2121
import com.lambda.event.listener.SafeListener.Companion.listen
2222
import com.lambda.gui.LambdaScreen
23+
import com.lambda.interaction.request.rotation.Rotation
24+
import com.lambda.interaction.request.rotation.RotationConfig
25+
import com.lambda.interaction.request.rotation.RotationManager.onRotate
26+
import com.lambda.interaction.request.rotation.RotationMode
27+
import com.lambda.interaction.request.rotation.visibilty.lookAt
2328
import com.lambda.module.Module
2429
import com.lambda.module.tag.ModuleTag
2530
import com.lambda.util.KeyboardUtils.isKeyPressed
2631
import com.lambda.util.math.MathUtils.toDouble
32+
import com.lambda.util.math.MathUtils.toFloatSign
2733
import com.lambda.util.player.MovementUtils.buildMovementInput
2834
import com.lambda.util.player.MovementUtils.mergeFrom
2935
import net.minecraft.client.gui.screen.ChatScreen
3036
import net.minecraft.client.gui.screen.Screen
3137
import net.minecraft.client.gui.screen.ingame.AnvilScreen
3238
import net.minecraft.client.gui.screen.ingame.CommandBlockScreen
39+
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen
3340
import net.minecraft.client.gui.screen.ingame.SignEditScreen
34-
import org.lwjgl.glfw.GLFW.GLFW_KEY_A
35-
import org.lwjgl.glfw.GLFW.GLFW_KEY_D
36-
import org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL
37-
import org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_SHIFT
38-
import org.lwjgl.glfw.GLFW.GLFW_KEY_S
39-
import org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE
40-
import org.lwjgl.glfw.GLFW.GLFW_KEY_W
41+
import net.minecraft.client.network.ClientPlayerEntity
42+
import org.lwjgl.glfw.GLFW.*
4143

4244
object InventoryMove : Module(
4345
name = "InventoryMove",
4446
description = "Allows you to move with GUIs opened",
4547
defaultTags = setOf(ModuleTag.PLAYER, ModuleTag.MOVEMENT)
4648
) {
47-
private val rotationSpeed by setting("Rotation Speed", 5, 1..20, 1, unit = "°/tick")
49+
private val speed by setting("Rotation Speed", 5, 1..20, 1, unit = "°/tick")
50+
private val rotationConfig = RotationConfig.Instant(RotationMode.Lock)
4851

4952
/**
5053
* Whether the current screen has text inputs or is null
@@ -70,18 +73,21 @@ object InventoryMove : Module(
7073
val jump = isKeyPressed(GLFW_KEY_SPACE)
7174
val sneak = isKeyPressed(GLFW_KEY_LEFT_SHIFT)
7275

73-
/*
74-
val pitch = rotationSpeed * (isKeyPressed(GLFW_KEY_DOWN).toFloatSign() -
75-
isKeyPressed(GLFW_KEY_UP).toFloatSign())
76-
val yaw = rotationSpeed * (isKeyPressed(GLFW_KEY_RIGHT).toFloatSign() -
77-
isKeyPressed(GLFW_KEY_LEFT).toFloatSign())
78-
79-
player.pitch = (player.pitch + pitch).coerceIn(-90f, 90f)
80-
player.yaw += yaw
81-
*/
82-
8376
player.isSprinting = isKeyPressed(GLFW_KEY_LEFT_CONTROL)
8477
event.input.mergeFrom(buildMovementInput(forward, strafe, jump, sneak))
8578
}
79+
80+
onRotate {
81+
if (mc.currentScreen.hasInputOrNull) return@onRotate
82+
83+
val pitch = (isKeyPressed(GLFW_KEY_DOWN, GLFW_KEY_KP_2).toFloatSign() -
84+
isKeyPressed(GLFW_KEY_UP, GLFW_KEY_KP_8).toFloatSign()) * speed
85+
val yaw = (isKeyPressed(GLFW_KEY_RIGHT, GLFW_KEY_KP_6).toFloatSign() -
86+
isKeyPressed(GLFW_KEY_LEFT, GLFW_KEY_KP_4).toFloatSign()) * speed
87+
88+
lookAt(
89+
Rotation(player.yaw + yaw, (player.pitch + pitch).coerceIn(-90f, 90f))
90+
).requestBy(rotationConfig)
91+
}
8692
}
8793
}

common/src/main/kotlin/com/lambda/util/KeyboardUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import net.minecraft.client.util.InputUtil
2222

2323
object KeyboardUtils {
2424
/**
25-
* Returns whether a key code (not scan code) is being pressed
25+
* Returns whether any of the key-codes (not scan-codes) are being pressed
2626
*/
27-
fun SafeContext.isKeyPressed(key: Int) =
28-
InputUtil.isKeyPressed(mc.window.handle, key)
27+
fun SafeContext.isKeyPressed(vararg keys: Int) =
28+
keys.any { InputUtil.isKeyPressed(mc.window.handle, it) }
2929
}

0 commit comments

Comments
 (0)