Skip to content

Commit 234629a

Browse files
committed
Merge branch '1.21.5' into fix/movement-processing
2 parents d1175fc + f45d35e commit 234629a

File tree

8 files changed

+70
-98
lines changed

8 files changed

+70
-98
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class MinecraftClientMixin {
5252
@Shadow
5353
@Nullable
5454
public Screen currentScreen;
55+
5556
@Shadow
5657
@Nullable
5758
public HitResult crosshairTarget;
@@ -135,6 +136,19 @@ private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
135136
}
136137
}
137138

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+
138152
@Redirect(method = "doAttack()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
139153
private void redirectHandSwing(ClientPlayerEntity instance, Hand hand) {
140154
if (this.crosshairTarget == null) return;
@@ -157,17 +171,4 @@ void injectFastPlace(CallbackInfo ci) {
157171

158172
itemUseCooldown = Interact.getPlaceDelay();
159173
}
160-
161-
@Redirect(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;unpressAll()V"))
162-
private void redirectUnPressAll() {
163-
if (InventoryMove.getShouldMove()) {
164-
KeyBinding.unpressAll();
165-
return;
166-
}
167-
for (KeyBinding bind : KeyBinding.KEYS_BY_ID.values()) {
168-
if (!InventoryMove.isKeyMovementRelated(bind.boundKey.getCode())) {
169-
bind.reset();
170-
}
171-
}
172-
}
173174
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ private void onKey(long window, int key, int scancode, int action, int modifiers
3535
EventFlow.post(new KeyboardEvent.Press(key, scancode, action, modifiers));
3636
}
3737

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+
3845
@Inject(method = "onChar", at = @At("HEAD"))
3946
private void onChar(long window, int codePoint, int modifiers, CallbackInfo ci) {
4047
char[] chars = Character.toChars(codePoint);
@@ -43,11 +50,4 @@ private void onChar(long window, int codePoint, int modifiers, CallbackInfo ci)
4350
EventFlow.post(new KeyboardEvent.Char(c));
4451
}
4552
}
46-
47-
@Inject(method = "onKey", at = @At("RETURN"))
48-
private void onKeyTail(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
49-
if (!InventoryMove.getShouldMove() || !InventoryMove.isKeyMovementRelated(key)) return;
50-
InputUtil.Key fromCode = InputUtil.fromKeyCode(key, scancode);
51-
KeyBinding.setKeyPressed(fromCode, action != 0);
52-
}
5353
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ abstract class AbstractSetting<T : Any>(
159159
}
160160

161161
fun group(path: NamedEnum?) = apply {
162-
if (path != null) {
163-
groups.add(listOf(path))
164-
}
162+
path?.let { groups.add(listOf(it)) }
165163
}
166164

167165
fun reset(silent: Boolean = false) {

src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 33 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ import com.lambda.interaction.request.breaking.BreakManager.breaks
5454
import com.lambda.interaction.request.breaking.BreakManager.canAccept
5555
import com.lambda.interaction.request.breaking.BreakManager.checkForCancels
5656
import com.lambda.interaction.request.breaking.BreakManager.initNewBreak
57-
import com.lambda.interaction.request.breaking.BreakManager.instantBreaks
5857
import com.lambda.interaction.request.breaking.BreakManager.maxBreaksThisTick
59-
import com.lambda.interaction.request.breaking.BreakManager.performInstantBreaks
60-
import com.lambda.interaction.request.breaking.BreakManager.processNewBreaks
58+
import com.lambda.interaction.request.breaking.BreakManager.processNewBreak
6159
import com.lambda.interaction.request.breaking.BreakManager.processRequest
6260
import com.lambda.interaction.request.breaking.BreakManager.simulateAbandoned
6361
import com.lambda.interaction.request.breaking.BreakManager.updateBreakProgress
@@ -94,7 +92,6 @@ import net.minecraft.util.math.Box
9492
import net.minecraft.world.BlockView
9593
import kotlin.math.max
9694

97-
// ToDo: Fix root cause of breaks becoming redundant while the actual state is empty
9895
object BreakManager : RequestHandler<BreakRequest>(
9996
0,
10097
TickEvent.Pre,
@@ -155,7 +152,6 @@ object BreakManager : RequestHandler<BreakRequest>(
155152
private var maxBreaksThisTick = 0
156153

157154
private var breaks = mutableListOf<BreakContext>()
158-
private var instantBreaks = mutableListOf<BreakContext>()
159155

160156
var lastPosStarted: BlockPos? = null
161157
set(value) {
@@ -185,7 +181,6 @@ object BreakManager : RequestHandler<BreakRequest>(
185181
}
186182
activeRequest = null
187183
breaks = mutableListOf()
188-
instantBreaks = mutableListOf()
189184
breaksThisTick = 0
190185
}
191186

@@ -313,37 +308,45 @@ object BreakManager : RequestHandler<BreakRequest>(
313308
* or the player needs to swap to a different hotbar slot.
314309
*
315310
* @see performInstantBreaks
316-
* @see processNewBreaks
311+
* @see processNewBreak
317312
* @see updateBreakProgress
318313
*/
319314
private fun SafeContext.processRequest(breakRequest: BreakRequest?) {
320315
breakRequest?.let { request ->
321316
if (request.fresh) populateFrom(request)
322317
}
323318

324-
repeat(2) {
325-
breakRequest?.let { request ->
326-
if (performInstantBreaks(request)) {
327-
processNewBreaks(request)
328-
}
329-
}
319+
var noNew = false
320+
var noProgression = false
321+
322+
while (true) {
323+
noNew = breakRequest?.let { request ->
324+
!processNewBreak(request)
325+
} != false
330326

331327
// Reversed so that the breaking order feels natural to the user as the primary break is always the
332328
// last break to be started
333-
if (handlePreProcessing()) {
329+
noProgression = if (handlePreProcessing()) {
334330
activeInfos
335-
.filter { it.updatedThisTick }
331+
.filter { it.updatedThisTick && it.shouldProgress }
336332
.asReversed()
337-
.forEach { info ->
338-
if (info.shouldProgress)
339-
updateBreakProgress(info)
333+
.run {
334+
if (isEmpty()) {
335+
true
336+
} else {
337+
forEach { info ->
338+
updateBreakProgress(info)
339+
}
340+
false
341+
}
340342
}
341-
}
342-
}
343+
} else true
343344

344-
if (instantBreaks.isEmpty() && breaks.isEmpty()) {
345-
activeRequest = null
345+
if (noNew && noProgression) break
346346
}
347+
348+
if (breaks.isEmpty()) activeRequest = null
349+
347350
if (breaksThisTick > 0 || activeInfos.isNotEmpty()) {
348351
activeThisTick = true
349352
}
@@ -384,12 +387,8 @@ object BreakManager : RequestHandler<BreakRequest>(
384387
}
385388
}
386389

387-
instantBreaks = newBreaks
388-
.filter { it.instantBreak }
389-
.toMutableList()
390-
391390
breaks = newBreaks
392-
.filter { !it.instantBreak }
391+
.sortedByDescending { it.instantBreak }
393392
.toMutableList()
394393

395394
val breakConfig = request.config
@@ -451,50 +450,22 @@ object BreakManager : RequestHandler<BreakRequest>(
451450
return true
452451
}
453452

454-
/**
455-
* Attempts to break as many [BreakContext]'s as possible from the [instantBreaks] collection within this tick.
456-
*
457-
* @return false if a break could not be performed.
458-
*/
459-
private fun SafeContext.performInstantBreaks(request: BreakRequest): Boolean {
460-
val iterator = instantBreaks.iterator()
461-
while (iterator.hasNext()) {
462-
if (breaksThisTick + 1 > maxBreaksThisTick) return false
463-
464-
val ctx = iterator.next()
465-
466-
if (!canAccept(ctx)) continue
467-
468-
rotationRequest = if (request.config.rotateForBreak) ctx.rotation.submit(false) else null
469-
if (!rotated || tickStage !in request.config.breakStageMask) return false
470-
471-
val breakInfo = initNewBreak(ctx, request) ?: return false
472-
if (!handlePreProcessing()) return false
473-
474-
updateBreakProgress(breakInfo)
475-
iterator.remove()
476-
}
477-
return true
478-
}
479-
480453
/**
481454
* Attempts to start breaking as many [BreakContext]'s from the [breaks] collection as possible.
482455
*
483456
* @return false if a context cannot be started or the maximum active breaks has been reached.
484457
*
485458
* @see initNewBreak
486459
*/
487-
private fun SafeContext.processNewBreaks(request: BreakRequest): Boolean {
488-
val iterator = breaks.iterator()
489-
while (iterator.hasNext()) {
490-
val ctx = iterator.next()
491-
492-
if (!canAccept(ctx)) continue
460+
private fun SafeContext.processNewBreak(request: BreakRequest): Boolean {
461+
breaks.forEach { ctx ->
462+
if (!canAccept(ctx)) return@forEach
493463

494464
initNewBreak(ctx, request) ?: return false
495-
iterator.remove()
465+
breaks.remove(ctx)
466+
return true
496467
}
497-
return true
468+
return false
498469
}
499470

500471
/**
@@ -517,10 +488,7 @@ object BreakManager : RequestHandler<BreakRequest>(
517488
} else return null
518489
}
519490

520-
if (!primaryInfo.breaking) {
521-
secondaryBreak = breakInfo.apply { type = Secondary }
522-
return secondaryBreak
523-
}
491+
if (!primaryInfo.breaking) return null
524492

525493
secondaryBreak = primaryInfo.apply { type = Secondary }
526494
secondaryBreak?.stopBreakPacket(world, interaction)

src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ data class SwapInfo(
6161

6262
val minKeepTicks = run {
6363
if (type == Primary) {
64-
val swapTickProgress = breakDelta * (breakTicks + breakConfig.serverSwapTicks - 1)
64+
val swapTickProgress = breakDelta * (breakTicks + breakConfig.serverSwapTicks - 1).coerceAtLeast(1)
6565
if (swapTickProgress >= threshold && swapStack.heldTicks < breakConfig.serverSwapTicks) 1
6666
else 0
6767
} else {
6868
val serverSwapTicks = breakConfig.serverSwapTicks.coerceAtLeast(3)
69-
val swapTickProgress = breakDelta * (breakTicks + serverSwapTicks - 1)
69+
val swapTickProgress = breakDelta * (breakTicks + serverSwapTicks - 1).coerceAtLeast(1)
7070
if (swapTickProgress >= threshold && swapStack.heldTicks < serverSwapTicks) 1
7171
else 0
7272
}

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

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

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

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@
1818
package com.lambda.module.modules.player
1919

2020
import com.lambda.Lambda.mc
21-
import com.lambda.config.groups.RotationSettings
22-
import com.lambda.event.events.UpdateManagerEvent
23-
import com.lambda.event.listener.SafeListener.Companion.listen
2421
import com.lambda.gui.LambdaScreen
2522
import com.lambda.interaction.request.rotating.Rotation
2623
import com.lambda.interaction.request.rotating.RotationConfig
24+
import com.lambda.interaction.request.rotating.RotationManager.onRotate
2725
import com.lambda.interaction.request.rotating.RotationMode
2826
import com.lambda.interaction.request.rotating.visibilty.lookAt
2927
import com.lambda.module.Module
3028
import com.lambda.module.tag.ModuleTag
3129
import com.lambda.util.KeyboardUtils.isKeyPressed
32-
import com.lambda.util.NamedEnum
3330
import com.lambda.util.math.MathUtils.toFloatSign
3431
import net.minecraft.client.gui.screen.ChatScreen
3532
import net.minecraft.client.gui.screen.Screen
@@ -70,8 +67,8 @@ object InventoryMove : Module(
7067
this == null
7168

7269
init {
73-
listen<UpdateManagerEvent.Rotation> {
74-
if (!arrowKeys || mc.currentScreen.hasInputOrNull) return@listen
70+
onRotate {
71+
if (!arrowKeys || mc.currentScreen.hasInputOrNull) return@onRotate
7572

7673
val pitch = (isKeyPressed(GLFW_KEY_DOWN, GLFW_KEY_KP_2).toFloatSign() -
7774
isKeyPressed(GLFW_KEY_UP, GLFW_KEY_KP_8).toFloatSign()) * speed

src/main/resources/lambda.accesswidener

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +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-
transitive-accessible field net/minecraft/client/option/KeyBinding KEYS_BY_ID Ljava/util/Map;
13-
transitive-accessible method net/minecraft/client/option/KeyBinding reset ()V
12+
accessible field net/minecraft/client/option/KeyBinding KEYS_BY_ID Ljava/util/Map;
13+
accessible method net/minecraft/client/option/KeyBinding reset ()V
1414

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

0 commit comments

Comments
 (0)