|
| 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 | +} |
0 commit comments