Skip to content

Commit aa45a02

Browse files
authored
Merge pull request #143
* use the players keybinds and use minecrafts bind handling to account … * use the players keybinds and use minecrafts bind handling to account … * reintroduce rotating with the arrow keys * rebase patches * use the players keybinds and use minecrafts bind handling to account … * use the players keybinds and use minecrafts bind handling to account … * Merge remote-tracking branch 'NeoLambda/improvement/inventory-move' i… * reintroduce rotating with the arrow keys * Merge remote-tracking branch 'NeoLambda/improvement/inventory-move' i… * constructors improvements * delete unused files * Use null pattern * Merge branch '1.21.5' into improvement/inventory-move
1 parent 4842d77 commit aa45a02

File tree

7 files changed

+74
-38
lines changed

7 files changed

+74
-38
lines changed

src/main/java/com/lambda/mixin/MinecraftClientMixin.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
package com.lambda.mixin;
1919

20-
import com.lambda.Lambda;
2120
import com.lambda.event.EventFlow;
2221
import com.lambda.event.events.ClientEvent;
2322
import com.lambda.event.events.InventoryEvent;
2423
import com.lambda.event.events.TickEvent;
2524
import com.lambda.gui.DearImGui;
2625
import com.lambda.module.modules.player.Interact;
26+
import com.lambda.module.modules.player.InventoryMove;
2727
import com.lambda.module.modules.player.PacketMine;
2828
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
2929
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
@@ -33,6 +33,7 @@
3333
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
3434
import net.minecraft.client.network.ClientPlayerEntity;
3535
import net.minecraft.client.network.ClientPlayerInteractionManager;
36+
import net.minecraft.client.option.KeyBinding;
3637
import net.minecraft.client.render.WorldRenderer;
3738
import net.minecraft.client.sound.SoundManager;
3839
import net.minecraft.util.Hand;
@@ -51,10 +52,14 @@ public class MinecraftClientMixin {
5152
@Shadow
5253
@Nullable
5354
public Screen currentScreen;
55+
5456
@Shadow
5557
@Nullable
5658
public HitResult crosshairTarget;
5759

60+
@Shadow
61+
public int itemUseCooldown;
62+
5863
@Inject(method = "close", at = @At("HEAD"))
5964
void closeImGui(CallbackInfo ci) {
6065
DearImGui.INSTANCE.destroy();
@@ -131,6 +136,19 @@ private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
131136
}
132137
}
133138

139+
@Redirect(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;unpressAll()V"))
140+
private void redirectUnPressAll() {
141+
if (!InventoryMove.getShouldMove()) {
142+
KeyBinding.unpressAll();
143+
return;
144+
}
145+
KeyBinding.KEYS_BY_ID.values().forEach(bind -> {
146+
if (!InventoryMove.isKeyMovementRelated(bind.boundKey.getCode())) {
147+
bind.reset();
148+
}
149+
});
150+
}
151+
134152
@Redirect(method = "doAttack()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
135153
private void redirectHandSwing(ClientPlayerEntity instance, Hand hand) {
136154
if (this.crosshairTarget == null) return;
@@ -151,6 +169,6 @@ boolean redirectMultiActon(ClientPlayerInteractionManager instance) {
151169
void injectFastPlace(CallbackInfo ci) {
152170
if (!Interact.INSTANCE.isEnabled()) return;
153171

154-
Lambda.getMc().itemUseCooldown = Interact.getPlaceDelay();
172+
itemUseCooldown = Interact.getPlaceDelay();
155173
}
156174
}

src/main/java/com/lambda/mixin/input/KeyboardMixin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
import com.lambda.event.EventFlow;
2121
import com.lambda.event.events.KeyboardEvent;
22+
import com.lambda.module.modules.player.InventoryMove;
2223
import net.minecraft.client.Keyboard;
24+
import net.minecraft.client.option.KeyBinding;
25+
import net.minecraft.client.util.InputUtil;
2326
import org.spongepowered.asm.mixin.Mixin;
2427
import org.spongepowered.asm.mixin.injection.At;
2528
import org.spongepowered.asm.mixin.injection.Inject;
@@ -32,6 +35,13 @@ private void onKey(long window, int key, int scancode, int action, int modifiers
3235
EventFlow.post(new KeyboardEvent.Press(key, scancode, action, modifiers));
3336
}
3437

38+
@Inject(method = "onKey", at = @At("RETURN"))
39+
private void onKeyTail(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
40+
if (!InventoryMove.getShouldMove() || !InventoryMove.isKeyMovementRelated(key)) return;
41+
InputUtil.Key fromCode = InputUtil.fromKeyCode(key, scancode);
42+
KeyBinding.setKeyPressed(fromCode, action != 0);
43+
}
44+
3545
@Inject(method = "onChar", at = @At("HEAD"))
3646
private void onChar(long window, int codePoint, int modifiers, CallbackInfo ci) {
3747
char[] chars = Character.toChars(codePoint);

src/main/kotlin/com/lambda/config/AbstractSetting.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ abstract class AbstractSetting<T : Any>(
158158
groups.add(path.toList())
159159
}
160160

161+
fun group(path: NamedEnum?) = apply {
162+
path?.let { groups.add(listOf(it)) }
163+
}
164+
161165
fun reset(silent: Boolean = false) {
162166
if (!silent && value == defaultValue) {
163167
ConfigCommand.info(notChangedMessage())

src/main/kotlin/com/lambda/config/groups/RotationSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import kotlin.random.Random
3030

3131
class RotationSettings(
3232
c: Configurable,
33-
baseGroup: NamedEnum,
33+
baseGroup: NamedEnum? = null,
3434
vis: () -> Boolean = { true }
3535
) : RotationConfig {
3636
override var rotationMode by c.setting("Mode", RotationMode.Sync, "How the player is being rotated on interaction", vis).group(baseGroup)

src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ object RotationManager : RequestHandler<RotationRequest>(
6161
var activeRequest: RotationRequest? = null
6262
private var changedThisTick = false
6363

64+
fun Any.onRotate(
65+
alwaysListen: Boolean = false,
66+
priority: Int = 0,
67+
block: SafeContext.() -> Unit
68+
) = this.listen<UpdateManagerEvent.Rotation>(priority, alwaysListen) {
69+
block()
70+
}
71+
6472
override fun load(): String {
6573
super.load()
6674

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

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,79 +17,58 @@
1717

1818
package 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
2321
import com.lambda.gui.LambdaScreen
2422
import com.lambda.interaction.request.rotating.Rotation
2523
import com.lambda.interaction.request.rotating.RotationConfig
24+
import com.lambda.interaction.request.rotating.RotationManager.onRotate
2625
import com.lambda.interaction.request.rotating.RotationMode
2726
import com.lambda.interaction.request.rotating.visibilty.lookAt
2827
import com.lambda.module.Module
2928
import com.lambda.module.tag.ModuleTag
3029
import com.lambda.util.KeyboardUtils.isKeyPressed
31-
import com.lambda.util.math.MathUtils.toDouble
3230
import com.lambda.util.math.MathUtils.toFloatSign
33-
import com.lambda.util.player.MovementUtils.update
3431
import net.minecraft.client.gui.screen.ChatScreen
3532
import net.minecraft.client.gui.screen.Screen
33+
import net.minecraft.client.gui.screen.ingame.AbstractCommandBlockScreen
34+
import net.minecraft.client.gui.screen.ingame.AbstractSignEditScreen
3635
import 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
4136
import org.lwjgl.glfw.GLFW.GLFW_KEY_DOWN
4237
import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_2
4338
import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_4
4439
import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_6
4540
import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_8
4641
import 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
4942
import 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
5243
import org.lwjgl.glfw.GLFW.GLFW_KEY_UP
53-
import org.lwjgl.glfw.GLFW.GLFW_KEY_W
5444

5545
object 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
}

src/main/resources/lambda.accesswidener

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ transitive-accessible field net/minecraft/client/input/Input movementVector Lnet
99
transitive-accessible field net/minecraft/client/MinecraftClient renderTaskQueue Ljava/util/Queue;
1010
transitive-accessible field net/minecraft/client/option/KeyBinding boundKey Lnet/minecraft/client/util/InputUtil$Key;
1111
transitive-accessible method net/minecraft/client/MinecraftClient getWindowTitle ()Ljava/lang/String;
12+
accessible field net/minecraft/client/option/KeyBinding KEYS_BY_ID Ljava/util/Map;
13+
accessible method net/minecraft/client/option/KeyBinding reset ()V
1214

1315
# World
1416
transitive-accessible field net/minecraft/client/world/ClientWorld entityManager Lnet/minecraft/world/entity/ClientEntityManager;

0 commit comments

Comments
 (0)