Skip to content

Commit 3ba8987

Browse files
committed
InventoryMove
1 parent 31c10f8 commit 3ba8987

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.player
19+
20+
import com.lambda.event.events.MovementEvent
21+
import com.lambda.event.listener.SafeListener.Companion.listen
22+
import com.lambda.gui.LambdaScreen
23+
import com.lambda.module.Module
24+
import com.lambda.module.tag.ModuleTag
25+
import com.lambda.util.KeyboardUtils.isKeyPressed
26+
import com.lambda.util.math.MathUtils.toDouble
27+
import com.lambda.util.player.MovementUtils.buildMovementInput
28+
import com.lambda.util.player.MovementUtils.mergeFrom
29+
import net.minecraft.client.gui.screen.ChatScreen
30+
import net.minecraft.client.gui.screen.Screen
31+
import net.minecraft.client.gui.screen.ingame.AnvilScreen
32+
import net.minecraft.client.gui.screen.ingame.CommandBlockScreen
33+
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+
42+
object InventoryMove : Module(
43+
name = "InventoryMove",
44+
description = "Allows you to move with GUIs opened",
45+
defaultTags = setOf(ModuleTag.PLAYER, ModuleTag.MOVEMENT)
46+
) {
47+
private val rotationSpeed by setting("Rotation Speed", 5, 1..20, 1, unit = "°/tick")
48+
49+
/**
50+
* Whether the current screen has text inputs or is null
51+
*/
52+
val Screen?.hasInputOrNull: Boolean
53+
get() = this is ChatScreen ||
54+
this is SignEditScreen ||
55+
this is AnvilScreen ||
56+
this is CommandBlockScreen ||
57+
this is LambdaScreen ||
58+
this == null
59+
60+
init {
61+
listen<MovementEvent.InputUpdate>(20250415) { event ->
62+
if (mc.currentScreen.hasInputOrNull) return@listen
63+
64+
val forward = isKeyPressed(GLFW_KEY_W).toDouble() -
65+
isKeyPressed(GLFW_KEY_S).toDouble()
66+
67+
val strafe = isKeyPressed(GLFW_KEY_A).toDouble() -
68+
isKeyPressed(GLFW_KEY_D).toDouble()
69+
70+
val jump = isKeyPressed(GLFW_KEY_SPACE)
71+
val sneak = isKeyPressed(GLFW_KEY_LEFT_SHIFT)
72+
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+
83+
player.isSprinting = isKeyPressed(GLFW_KEY_LEFT_CONTROL)
84+
event.input.mergeFrom(buildMovementInput(forward, strafe, jump, sneak))
85+
}
86+
}
87+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.util
19+
20+
import com.lambda.context.SafeContext
21+
import net.minecraft.client.util.InputUtil
22+
23+
object KeyboardUtils {
24+
/**
25+
* Returns whether a key code (not scan code) is being pressed
26+
*/
27+
fun SafeContext.isKeyPressed(key: Int) =
28+
InputUtil.isKeyPressed(mc.window.handle, key)
29+
}

common/src/main/kotlin/com/lambda/util/math/MathUtils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ object MathUtils {
3737

3838
fun Boolean.toInt() = if (this) 1 else 0
3939
fun Boolean.toIntSign() = if (this) 1 else -1
40+
fun Boolean.toFloat() = if (this) 1f else 0f
41+
fun Boolean.toFloatSign() = if (this) 1f else -1f
42+
fun Boolean.toDouble() = if (this) 1.0 else 0.0
43+
fun Boolean.toDoubleSign() = if (this) 1.0 else -1.0
4044

4145
fun Double.floorToInt() = floor(this).toInt()
4246
fun Double.ceilToInt() = ceil(this).toInt()

0 commit comments

Comments
 (0)