Skip to content

Commit a60fe87

Browse files
committed
min server swap ticks to 2 for secondary breaks allowing for faster primary breaks as to not drag them down
1 parent 09b96de commit a60fe87

File tree

1 file changed

+11
-8
lines changed
  • src/main/kotlin/com/lambda/interaction/request/breaking

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ import net.minecraft.item.ItemStack
2626
import net.minecraft.world.BlockView
2727

2828
data class SwapInfo(
29+
val type: BreakInfo.BreakType,
2930
val breakConfig: BreakConfig = TaskFlowModule.build.breaking,
3031
val swap: Boolean = false,
3132
val minKeepTicks: Int = 0,
3233
) {
3334
val canCompleteBreak
34-
get() = BreakManager.heldTicks >= breakConfig.serverSwapTicks
35+
get() = BreakManager.heldTicks >= if (type == Primary)
36+
breakConfig.serverSwapTicks
37+
else breakConfig.serverSwapTicks.coerceAtLeast(2)
3538

3639
companion object {
37-
val EMPTY = SwapInfo()
40+
val EMPTY = SwapInfo(Primary)
3841

3942
fun getSwapInfo(
4043
info: BreakInfo,
@@ -46,22 +49,22 @@ data class SwapInfo(
4649
val breakDeltaNoEfficiency = context.cachedState
4750
.calcItemBlockBreakingDelta(player, world, context.blockPos, swapStack, ignoreEfficiency = true)
4851
val breakTicks = (if (rebreakPotential.isPossible()) RebreakManager.rebreak?.breakingTicks
49-
?: throw IllegalStateException("Rebreak was null when rebreak was considered possible")
52+
?: throw IllegalStateException("Rebreak BreakInfo was null when rebreak was considered possible")
5053
else breakingTicks).let {
5154
// Plus one as this is calculated before this ticks progress is calculated and the breakingTicks are incremented
5255
(it + 1) - breakConfig.fudgeFactor
5356
}
5457
val threshold = getBreakThreshold()
5558

5659
val minKeepTicks = run {
57-
val swapTickProgress = breakDelta * (breakTicks + breakConfig.serverSwapTicks)
58-
val withinPrimarySwapRange = swapTickProgress >= threshold
5960
if (type == Primary) {
61+
val swapTickProgress = breakDelta * (breakTicks + breakConfig.serverSwapTicks)
6062
val withoutEfficiency = breakDeltaNoEfficiency * breakTicks >= threshold
61-
if (withinPrimarySwapRange && !withoutEfficiency && swapStack.heldTicks < breakConfig.serverSwapTicks) 1
63+
if (swapTickProgress >= threshold && !withoutEfficiency && swapStack.heldTicks < breakConfig.serverSwapTicks) 1
6264
else 0
6365
} else {
64-
val withinSecondarySwapRange = withinPrimarySwapRange ||
66+
val swapTickProgress = breakDelta * (breakTicks + breakConfig.serverSwapTicks.coerceAtLeast(2) - 1)
67+
val withinSecondarySwapRange = swapTickProgress >= threshold ||
6568
(breakDelta * breakTicks >= threshold && breakDelta * (breakTicks - 1) < threshold)
6669
if (withinSecondarySwapRange) 1 else 0
6770
}
@@ -79,7 +82,7 @@ data class SwapInfo(
7982
BreakConfig.SwapMode.Constant -> true
8083
}
8184

82-
return SwapInfo(breakConfig, swap, minKeepTicks)
85+
return SwapInfo(info.type, breakConfig, swap, minKeepTicks)
8386
}
8487

8588
private val ItemStack.heldTicks

0 commit comments

Comments
 (0)