Skip to content

Commit 3166c0c

Browse files
committed
*almost* complete silent swap with double break and fixed listener i forgot to add .Pre on
1 parent d9408e3 commit 3166c0c

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ data class BreakContext(
8484
withState(checkedState, expectedPos, sideColor, result.side)
8585
}
8686

87-
fun requestDependencies(request: BreakRequest): Boolean {
88-
val hotbarRequest = request.hotbar.request(HotbarRequest(hotbarIndex, request.hotbar), false)
89-
return hotbarRequest.done
87+
fun requestDependencies(breakRequest: BreakRequest, minKeepTicks: Int = 0): Boolean {
88+
val request = HotbarRequest(hotbarIndex, breakRequest.hotbar, breakRequest.hotbar.keepTicks.coerceAtLeast(minKeepTicks))
89+
return request.hotbar.request(request, false).done
9090
}
9191
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import com.lambda.interaction.request.placing.PlaceManager
4747
import com.lambda.interaction.request.rotation.RotationRequest
4848
import com.lambda.threading.runSafe
4949
import com.lambda.util.BlockUtils.blockState
50-
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
5150
import com.lambda.util.Communication.warn
5251
import com.lambda.util.item.ItemUtils.block
5352
import com.lambda.util.player.gamemode
@@ -227,7 +226,12 @@ object BreakManager : RequestHandler<BreakRequest>(
227226
.asReversed()
228227
.forEach { info ->
229228
if (info.updatedProgressThisTick) return@forEach
230-
if (!info.context.requestDependencies(info.request)) return@run
229+
val minKeepTicks = if (info.isSecondary) {
230+
val breakDelta = info.context.checkedState.calcBlockBreakingDelta(player, world, info.context.expectedPos)
231+
val breakAmount = breakDelta * info.breakingTicks
232+
if (breakAmount >= 1.0f) 1 else 0
233+
} else 0
234+
if (!info.context.requestDependencies(info.request, minKeepTicks)) return@run
231235
if (tickStage !in info.breakConfig.breakStageMask) return@forEach
232236
if ((!rotated && info.isPrimary)) return@run
233237

@@ -545,11 +549,10 @@ object BreakManager : RequestHandler<BreakRequest>(
545549
}
546550

547551
info.breakingTicks++
548-
val progress = blockState.calcItemBlockBreakingDelta(
552+
val progress = blockState.calcBlockBreakingDelta(
549553
player,
550554
world,
551-
ctx.expectedPos,
552-
player.mainHandStack
555+
ctx.expectedPos
553556
) * if (info.isSecondary || info.isRedundant) {
554557
info.breakingTicks - info.breakConfig.doubleBreakFudgeFactor
555558
} else info.breakingTicks
@@ -637,7 +640,7 @@ object BreakManager : RequestHandler<BreakRequest>(
637640
blockState.onBlockBreakStart(world, ctx.expectedPos, player)
638641
}
639642

640-
val breakDelta = blockState.calcItemBlockBreakingDelta(player, world, ctx.expectedPos, player.mainHandStack)
643+
val breakDelta = blockState.calcBlockBreakingDelta(player, world, ctx.expectedPos)
641644
if (notAir && breakDelta >= info.getBreakThreshold()) {
642645
onBlockBreak(info)
643646
} else {

common/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
5858
override fun load(): String {
5959
super.load()
6060

61-
listen<TickEvent>(priority = Int.MAX_VALUE) {
61+
listen<TickEvent.Pre>(priority = Int.MAX_VALUE) {
6262
activeRequest?.let { activeInfo ->
6363
if (activeInfo.keepTicks <= 0) {
6464
activeRequest = null

0 commit comments

Comments
 (0)