Skip to content

Commit 01603a5

Browse files
committed
constructors improvements
1 parent b453a75 commit 01603a5

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,27 @@
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;
3030
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
31-
import com.lambda.module.modules.player.InventoryMove;
3231
import net.minecraft.client.MinecraftClient;
3332
import net.minecraft.client.gui.screen.Screen;
3433
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
3534
import net.minecraft.client.network.ClientPlayerEntity;
3635
import net.minecraft.client.network.ClientPlayerInteractionManager;
36+
import net.minecraft.client.option.KeyBinding;
3737
import net.minecraft.client.render.WorldRenderer;
3838
import net.minecraft.client.sound.SoundManager;
3939
import net.minecraft.util.Hand;
4040
import net.minecraft.util.hit.HitResult;
41-
import net.minecraft.client.option.KeyBinding;
4241
import net.minecraft.util.thread.ThreadExecutor;
4342
import org.jetbrains.annotations.Nullable;
4443
import org.spongepowered.asm.mixin.Mixin;
@@ -53,10 +52,14 @@ public class MinecraftClientMixin {
5352
@Shadow
5453
@Nullable
5554
public Screen currentScreen;
55+
5656
@Shadow
5757
@Nullable
5858
public HitResult crosshairTarget;
5959

60+
@Shadow
61+
public int itemUseCooldown;
62+
6063
@Inject(method = "close", at = @At("HEAD"))
6164
void closeImGui(CallbackInfo ci) {
6265
DearImGui.INSTANCE.destroy();
@@ -135,7 +138,7 @@ private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
135138

136139
@Redirect(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;unpressAll()V"))
137140
private void redirectUnPressAll() {
138-
if (InventoryMove.INSTANCE.isDisabled() || InventoryMove.hasInputOrNull(currentScreen)) {
141+
if (!InventoryMove.getShouldMove()) {
139142
KeyBinding.unpressAll();
140143
return;
141144
}
@@ -166,6 +169,6 @@ boolean redirectMultiActon(ClientPlayerInteractionManager instance) {
166169
void injectFastPlace(CallbackInfo ci) {
167170
if (!Interact.INSTANCE.isEnabled()) return;
168171

169-
Lambda.getMc().itemUseCooldown = Interact.getPlaceDelay();
172+
itemUseCooldown = Interact.getPlaceDelay();
170173
}
171174
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import org.spongepowered.asm.mixin.injection.Inject;
2929
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3030

31-
import static com.lambda.Lambda.getMc;
32-
3331
@Mixin(Keyboard.class)
3432
public class KeyboardMixin {
3533
@Inject(method = "onKey", at = @At("HEAD"))
@@ -39,11 +37,9 @@ private void onKey(long window, int key, int scancode, int action, int modifiers
3937

4038
@Inject(method = "onKey", at = @At("RETURN"))
4139
private void onKeyTail(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
42-
if (InventoryMove.INSTANCE.isDisabled() || InventoryMove.hasInputOrNull(getMc().currentScreen)) return;
43-
if (InventoryMove.isKeyMovementRelated(key)) {
44-
InputUtil.Key fromCode = InputUtil.fromKeyCode(key, scancode);
45-
KeyBinding.setKeyPressed(fromCode, action != 0);
46-
}
40+
if (!InventoryMove.getShouldMove() || !InventoryMove.isKeyMovementRelated(key)) return;
41+
InputUtil.Key fromCode = InputUtil.fromKeyCode(key, scancode);
42+
KeyBinding.setKeyPressed(fromCode, action != 0);
4743
}
4844

4945
@Inject(method = "onChar", at = @At("HEAD"))

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

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

161+
fun group(path: NamedEnum?) = apply {
162+
if (path != null) {
163+
groups.add(listOf(path))
164+
}
165+
}
166+
161167
fun reset(silent: Boolean = false) {
162168
if (!silent && value == defaultValue) {
163169
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/module/modules/player/InventoryMove.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import com.lambda.util.KeyboardUtils.isKeyPressed
3030
import com.lambda.util.math.MathUtils.toFloatSign
3131
import net.minecraft.client.gui.screen.ChatScreen
3232
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
3335
import net.minecraft.client.gui.screen.ingame.AnvilScreen
34-
import net.minecraft.client.gui.screen.ingame.CommandBlockScreen
35-
import net.minecraft.client.gui.screen.ingame.SignEditScreen
3636
import org.lwjgl.glfw.GLFW.GLFW_KEY_DOWN
3737
import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_2
3838
import org.lwjgl.glfw.GLFW.GLFW_KEY_KP_4
@@ -51,9 +51,24 @@ object InventoryMove : Module(
5151
private val speed by setting("Rotation Speed", 5, 1..20, 1, unit = "°/tick") { arrowKeys }
5252
private val rotationConfig = RotationConfig.Instant(RotationMode.Lock)
5353

54+
@JvmStatic
55+
val shouldMove get() = isEnabled && !mc.currentScreen.hasInputOrNull
56+
57+
/**
58+
* Whether the current screen has text inputs or is null
59+
*/
60+
@JvmStatic
61+
val Screen?.hasInputOrNull: Boolean
62+
get() = this is ChatScreen ||
63+
this is AbstractSignEditScreen ||
64+
this is AnvilScreen ||
65+
this is AbstractCommandBlockScreen ||
66+
this is LambdaScreen ||
67+
this == null
68+
5469
init {
5570
onRotate {
56-
if (!arrowKeys || hasInputOrNull(mc.currentScreen)) return@onRotate
71+
if (!arrowKeys || mc.currentScreen.hasInputOrNull) return@onRotate
5772

5873
val pitch = (isKeyPressed(GLFW_KEY_DOWN, GLFW_KEY_KP_2).toFloatSign() -
5974
isKeyPressed(GLFW_KEY_UP, GLFW_KEY_KP_8).toFloatSign()) * speed
@@ -66,18 +81,6 @@ object InventoryMove : Module(
6681
}
6782
}
6883

69-
/**
70-
* Whether the current screen has text inputs or is null
71-
*/
72-
@JvmStatic
73-
fun hasInputOrNull(screen: Screen?) =
74-
screen is ChatScreen ||
75-
screen is SignEditScreen ||
76-
screen is AnvilScreen ||
77-
screen is CommandBlockScreen ||
78-
screen is LambdaScreen ||
79-
screen == null
80-
8184
@JvmStatic
8285
fun isKeyMovementRelated(key: Int): Boolean {
8386
val options = mc.options

0 commit comments

Comments
 (0)