Skip to content

Commit 6c1d57f

Browse files
committed
small fixes and improvements
1 parent d15a805 commit 6c1d57f

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,14 @@ object BreakManager : RequestHandler<BreakRequest>(
429429

430430
infos.firstOrNull()?.let { info ->
431431
infos.lastOrNull { it.swapInfo.swap && it.shouldProgress }?.let { last ->
432-
val minSwapTicks = max(info.swapInfo.minKeepTicks, last.swapInfo.minKeepTicks)
432+
val minKeepTicks = if (info.swapInfo.longSwap || last.swapInfo.longSwap) 1 else 0
433+
val serverSwapTicks = max(info.breakConfig.serverSwapTicks, last.breakConfig.serverSwapTicks)
433434
hotbarRequest = with(info) {
434435
HotbarRequest(
435436
context.hotbarIndex,
436437
request.hotbar,
437-
request.hotbar.keepTicks.coerceAtLeast(minSwapTicks),
438-
request.config.serverSwapTicks - 1
438+
request.hotbar.keepTicks.coerceAtLeast(minKeepTicks),
439+
serverSwapTicks - 1
439440
).submit(false)
440441
}
441442
logger.debug("Submitted hotbar request", hotbarRequest)
@@ -656,16 +657,12 @@ object BreakManager : RequestHandler<BreakRequest>(
656657
info.progressedThisTick = true
657658

658659
if (!info.breaking) {
659-
if (!startBreaking(info)) {
660+
return if (startBreaking(info)) true
661+
else {
660662
info.nullify()
661663
info.request.onCancel?.invoke(ctx.blockPos)
662-
return false
664+
false
663665
}
664-
val swing = config.swing
665-
if (swing.isEnabled() && (swing != BreakConfig.SwingMode.End || info.type == Rebreak)) {
666-
swingHand(config.swingType, Hand.MAIN_HAND)
667-
}
668-
return true
669666
}
670667

671668
if (config.swapMode == BreakConfig.SwapMode.Constant && !swapped) return true
@@ -677,9 +674,7 @@ object BreakManager : RequestHandler<BreakRequest>(
677674
lastPosStarted = ctx.blockPos
678675
onBlockBreak(info)
679676
info.startBreakPacket(world, interaction)
680-
if (config.swing.isEnabled()) {
681-
swingHand(config.swingType, Hand.MAIN_HAND)
682-
}
677+
if (config.swing.isEnabled()) swingHand(config.swingType, Hand.MAIN_HAND)
683678
return true
684679
}
685680

@@ -786,6 +781,8 @@ object BreakManager : RequestHandler<BreakRequest>(
786781
onBlockBreak(info)
787782
info.startBreakPacket(world, interaction)
788783
breakCooldown = info.breakConfig.breakDelay
784+
val swing = info.breakConfig.swing
785+
if (swing.isEnabled()) swingHand(info.breakConfig.swingType, Hand.MAIN_HAND)
789786
return true
790787
}
791788
if (info.breaking) return false
@@ -831,6 +828,11 @@ object BreakManager : RequestHandler<BreakRequest>(
831828
info.stopBreakPacket(world, interaction)
832829
}
833830

831+
val swing = info.breakConfig.swing
832+
if (swing.isEnabled() && (swing != BreakConfig.SwingMode.End || instantBreakable)) {
833+
swingHand(info.breakConfig.swingType, Hand.MAIN_HAND)
834+
}
835+
834836
return true
835837
}
836838

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,22 @@ package com.lambda.interaction.request.breaking
2020
import com.lambda.interaction.request.LogContext
2121
import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder
2222
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary
23+
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Secondary
2324
import com.lambda.interaction.request.breaking.BreakManager.calcBreakDelta
24-
import com.lambda.interaction.request.hotbar.HotbarConfig
2525
import com.lambda.module.modules.client.TaskFlowModule
2626
import net.minecraft.client.network.ClientPlayerEntity
2727
import net.minecraft.world.BlockView
2828

2929
data class SwapInfo(
3030
private val type: BreakInfo.BreakType,
31-
private val hotbarConfig: HotbarConfig = TaskFlowModule.hotbar,
31+
private val breakConfig: BreakConfig = TaskFlowModule.build.breaking,
3232
val swap: Boolean = false,
33-
val minKeepTicks: Int = 0,
33+
val longSwap: Boolean = false
3434
) : LogContext {
3535
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
3636
group("Swap Info") {
3737
value("Type", type)
3838
value("Swap", swap)
39-
value("Min Keep Ticks", minKeepTicks)
4039
}
4140
}
4241

@@ -58,32 +57,30 @@ data class SwapInfo(
5857
?: throw IllegalStateException("Rebreak BreakInfo was null when rebreak was considered possible")
5958
else breakingTicks) + 1 - breakConfig.fudgeFactor
6059

61-
val minKeepTicks = run {
62-
if (type == Primary) {
63-
val swapTickProgress = breakDelta * (breakTicks + request.config.serverSwapTicks - 1).coerceAtLeast(1)
64-
if (swapTickProgress >= threshold && request.config.serverSwapTicks > 0) 1
65-
else 0
66-
} else {
60+
val swapAtEnd = run {
61+
val swapTickProgress = if (type == Primary)
62+
breakDelta * (breakTicks + request.config.serverSwapTicks - 1).coerceAtLeast(1)
63+
else {
6764
val serverSwapTicks = request.hotbar.swapPause.coerceAtLeast(3)
68-
val swapTickProgress = breakDelta * (breakTicks + serverSwapTicks - 1).coerceAtLeast(1)
69-
if (swapTickProgress >= threshold) 1
70-
else 0
65+
breakDelta * (breakTicks + serverSwapTicks - 1).coerceAtLeast(1)
7166
}
67+
swapTickProgress >= threshold
7268
}
7369

74-
val swapAtEnd = breakDelta * breakTicks >= threshold || minKeepTicks > 0
75-
76-
val swap = if (rebreakPotential == RebreakHandler.RebreakPotential.Instant)
77-
breakConfig.swapMode.isEnabled()
78-
else when (breakConfig.swapMode) {
70+
val swap = when (breakConfig.swapMode) {
7971
BreakConfig.SwapMode.None -> false
8072
BreakConfig.SwapMode.Start -> !breaking
8173
BreakConfig.SwapMode.End -> swapAtEnd
8274
BreakConfig.SwapMode.StartAndEnd -> !breaking || swapAtEnd
8375
BreakConfig.SwapMode.Constant -> true
8476
}
8577

86-
return SwapInfo(info.type, request.hotbar, swap, minKeepTicks)
78+
return SwapInfo(
79+
info.type,
80+
request.config,
81+
swap,
82+
breakConfig.serverSwapTicks > 0 || (info.type == Secondary && swapAtEnd)
83+
)
8784
}
8885
}
8986
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,17 @@ object PacketMine : Module(
195195
breakRequest(
196196
breakContexts, pendingInteractions, rotation, hotbar, interact, inventory, build,
197197
) {
198-
onStart { queuePositions.removePos(it); addBreak(it) }
199-
onUpdate { queuePositions.removePos(it) }
198+
onStart { queuePositions.removePos(it)
199+
if (breakPositions.none { pos -> pos == it }) {
200+
addBreak(it)
201+
}
202+
}
203+
onUpdate {
204+
queuePositions.removePos(it)
205+
if (breakPositions.none { pos -> pos == it }) {
206+
addBreak(it)
207+
}
208+
}
200209
onStop { removeBreak(it); breaks++ }
201210
onCancel { removeBreak(it, true) }
202211
onReBreakStart { reBreakPos = it }

0 commit comments

Comments
 (0)