Skip to content

Commit 62ba701

Browse files
committed
fix kill aura swapping after rotation is successful causing large hit delays when looking between lots of targets
1 parent f2e1877 commit 62ba701

File tree

3 files changed

+17
-38
lines changed

3 files changed

+17
-38
lines changed

src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.lambda.event.events.InventoryEvent;
2222
import com.lambda.event.events.PlayerEvent;
2323
import com.lambda.interaction.managers.inventory.InventoryManager;
24-
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2524
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
2625
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2726
import net.minecraft.client.network.ClientPlayerEntity;
@@ -30,7 +29,6 @@
3029
import net.minecraft.client.world.ClientWorld;
3130
import net.minecraft.entity.Entity;
3231
import net.minecraft.entity.player.PlayerEntity;
33-
import net.minecraft.entity.player.PlayerInventory;
3432
import net.minecraft.screen.slot.SlotActionType;
3533
import net.minecraft.stat.StatHandler;
3634
import net.minecraft.util.ActionResult;
@@ -51,6 +49,9 @@ public class ClientPlayInteractionManagerMixin {
5149
@Shadow
5250
public float currentBreakingProgress;
5351

52+
@Shadow
53+
public int lastSelectedSlot;
54+
5455
@Inject(method = "interactBlock", at = @At("HEAD"), cancellable = true)
5556
public void interactBlockHead(final ClientPlayerEntity player, final Hand hand, final BlockHitResult hitResult, final CallbackInfoReturnable<ActionResult> cir) {
5657
if (EventFlow.post(new PlayerEvent.Interact.Block(hand, hitResult)).isCanceled()) {
@@ -103,9 +104,9 @@ public void clickSlotHead(int syncId, int slotId, int button, SlotActionType act
103104
* }
104105
* }</pre>
105106
*/
106-
@ModifyExpressionValue(method = "syncSelectedSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;getSelectedSlot()I"))
107-
public int overrideSelectedSlotSync(int original) {
108-
return EventFlow.post(new InventoryEvent.HotbarSlot.Update(original)).getSlot();
107+
@Inject(method = "syncSelectedSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", shift = At.Shift.BEFORE))
108+
public void overrideSelectedSlotSync(CallbackInfo ci) {
109+
EventFlow.post(new InventoryEvent.HotbarSlot.Update(lastSelectedSlot));
109110
}
110111

111112
@Inject(method = "updateBlockBreakingProgress", at = @At("HEAD"), cancellable = true)

src/main/kotlin/com/lambda/event/events/InventoryEvent.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,7 @@ sealed class InventoryEvent {
8888
*
8989
* Updated slot id will come to the server if it defers from last reported slot.
9090
*/
91-
data class Update(var slot: Int) : HotbarSlot()
92-
93-
/**
94-
* Represents an event triggered when the client sends slot update to the server.
95-
*
96-
* This event happens when last slot defers from the previous one
97-
*/
98-
data class Changed(var slot: Int) : HotbarSlot()
91+
data class Update(val slot: Int) : HotbarSlot()
9992

10093
/**
10194
* Represents an event triggered when the server forces the player to change active hotbar slot.

src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
2121
import com.lambda.config.applyEdits
2222
import com.lambda.config.groups.Targeting
2323
import com.lambda.context.SafeContext
24-
import com.lambda.event.events.PlayerPacketEvent
24+
import com.lambda.event.events.InventoryEvent
2525
import com.lambda.event.events.TickEvent
2626
import com.lambda.event.listener.SafeListener.Companion.listen
2727
import com.lambda.interaction.managers.hotbar.HotbarRequest
@@ -67,10 +67,7 @@ object KillAura : Module(
6767

6868
private var lastAttackTime = 0L
6969
private var hitDelay = 100.0
70-
71-
private var prevY = 0.0
72-
private var lastY = 0.0
73-
private var lastOnGround = true
70+
private var cooldownFromSwap = false
7471

7572
enum class Group(override val displayName: String) : NamedEnum {
7673
General("General"),
@@ -98,21 +95,17 @@ object KillAura : Module(
9895
}
9996
}
10097

101-
listen<PlayerPacketEvent.Pre>(Int.MIN_VALUE) { event ->
102-
prevY = lastY
103-
lastY = event.position.y
104-
lastOnGround = event.onGround
105-
}
98+
listen<InventoryEvent.HotbarSlot.Update> { cooldownFromSwap = true }
10699

107100
listen<TickEvent.Input.Post> {
108101
target?.let { entity ->
109102
// Wait until the rotation has a hit result on the entity
103+
var rotated = true
110104
if (rotate) runSafeAutomated {
111105
val rotationRequest = lookAtEntity(entity)?.rotation?.let { rotationRequest { rotation(it) } }?.submit() ?: return@listen
112-
val cantContinue = !rotationRequest.done || entity !== prevEntity || !validServerRot
106+
rotated = rotationRequest.done && entity === prevEntity && validServerRot
113107
prevEntity = entity
114108
validServerRot = rotationRequest.done
115-
if (cantContinue) return@listen
116109
}
117110

118111
if (swap) {
@@ -126,12 +119,16 @@ object KillAura : Module(
126119
}
127120
}
128121

122+
if (!rotated) return@listen
123+
129124
// Cooldown check
130125
when (attackMode) {
131-
AttackMode.Cooldown -> if (player.getAttackCooldownProgress(0.5f) + (cooldownShrink / 20f) < 1.0f) return@listen
126+
AttackMode.Cooldown -> if (player.getAttackCooldownProgress(0.5f) + (cooldownShrink / 20f) < 1.0f && !cooldownFromSwap) return@listen
132127
AttackMode.Delay -> if (System.currentTimeMillis() - lastAttackTime < hitDelay) return@listen
133128
}
134129

130+
cooldownFromSwap = false
131+
135132
// Attack
136133
connection.sendPacket(PlayerInteractEntityC2SPacket.attack(target, player.isSneaking))
137134
if (interaction.gameMode != GameMode.SPECTATOR) {
@@ -144,17 +141,5 @@ object KillAura : Module(
144141
hitDelay = (hitDelay1..hitDelay2).random() * 50
145142
}
146143
}
147-
148-
onEnable { reset() }
149-
onDisable { reset() }
150-
}
151-
152-
private fun reset() {
153-
lastY = 0.0
154-
prevY = 0.0
155-
lastOnGround = true
156-
157-
lastAttackTime = 0L
158-
hitDelay = 100.0
159144
}
160145
}

0 commit comments

Comments
 (0)