@@ -36,6 +36,8 @@ import com.lambda.interaction.construction.context.BreakContext
3636import com.lambda.interaction.construction.result.BreakResult
3737import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
3838import com.lambda.interaction.construction.verify.TargetState
39+ import com.lambda.interaction.material.StackSelection
40+ import com.lambda.interaction.material.StackSelection.Companion.select
3941import com.lambda.interaction.request.ManagerUtils.isPosBlocked
4042import com.lambda.interaction.request.PositionBlocking
4143import com.lambda.interaction.request.RequestHandler
@@ -102,6 +104,14 @@ object BreakManager : RequestHandler<BreakRequest>(
102104 get() = breakInfos[1 ]
103105 set(value) { breakInfos[1 ] = value }
104106 private val breakInfos = arrayOfNulls<BreakInfo >(2 )
107+ val currentStackSelection
108+ get() = breakInfos
109+ .lastOrNull {
110+ it?.breakConfig?.doubleBreak == true || it?.isSecondary == true
111+ }?.context?.itemSelection
112+ ? : StackSelection .EVERYTHING .select()
113+ val currentContext
114+ get() = breakInfos.lastOrNull()?.context
105115
106116 private val pendingBreakCount get() = breakInfos.count { it != null } + pendingActions.size
107117 override val blockedPositions
@@ -294,7 +304,7 @@ object BreakManager : RequestHandler<BreakRequest>(
294304 } else 0
295305 if (! info.context.requestDependencies(info.request, minKeepTicks)) return @run
296306 if (tickStage !in info.breakConfig.breakStageMask) return @forEach
297- if (( ! rotated && info.isPrimary) ) return @run
307+ if (! rotated && info.isPrimary) return @run
298308
299309 updateBreakProgress(info)
300310 }
@@ -323,6 +333,7 @@ object BreakManager : RequestHandler<BreakRequest>(
323333 .simulate(player.eyePos, interact, rotation, inventory, build)
324334 .asSequence()
325335 .filterIsInstance<BreakResult .Break >()
336+ .filter { canAccept(it.context) }
326337 .sorted()
327338 .let { sim ->
328339 info.updateInfo(sim.firstOrNull()?.context ? : return @forEach)
@@ -354,7 +365,7 @@ object BreakManager : RequestHandler<BreakRequest>(
354365 // Sanitize the new breaks
355366 val newBreaks = request.contexts
356367 .distinctBy { it.blockPos }
357- .filter { ctx -> canAccept(ctx, request.config ) }
368+ .filter { ctx -> canAccept(ctx) }
358369 .let { acceptable ->
359370 acceptable.firstOrNull()?.let { first ->
360371 acceptable.filter { it.hotbarIndex == first.hotbarIndex }
@@ -398,19 +409,23 @@ object BreakManager : RequestHandler<BreakRequest>(
398409 /* *
399410 * @return if the break context can be accepted.
400411 */
401- private fun SafeContext.canAccept (ctx : BreakContext , breakConfig : BreakConfig ): Boolean {
402- if (breakInfos.none { it?.context?.blockPos == ctx .blockPos } && isPosBlocked(ctx .blockPos)) return false
412+ private fun SafeContext.canAccept (newCtx : BreakContext ): Boolean {
413+ if (breakInfos.none { it?.context?.blockPos == newCtx .blockPos } && isPosBlocked(newCtx .blockPos)) return false
403414
404- if (breakConfig.doubleBreak) {
405- breakInfos
406- .firstOrNull { it != null && ! it.isRedundant }
407- ?.let { info ->
408- if (ctx.hotbarIndex != info.context.hotbarIndex) return false
409- }
410- }
415+ breakInfos
416+ .lastOrNull { it != null && ! it.isRedundant && it.breakConfig.doubleBreak }
417+ ?.let { info ->
418+ val currentCtx = info.context
419+ val currentStack = player.inventory.getStack(currentCtx.hotbarIndex)
420+ val currentSpeed = currentCtx.cachedState.calcItemBlockBreakingDelta(player, world, currentCtx.blockPos, currentStack)
421+ val newStack = player.inventory.getStack(newCtx.hotbarIndex)
422+ val newSpeed = currentCtx.cachedState.calcItemBlockBreakingDelta(player, world, info.context.blockPos, newStack)
423+ if (! currentCtx.itemSelection.filterStack(newStack) || newSpeed < currentSpeed)
424+ return false
425+ }
411426
412- val blockState = blockState(ctx .blockPos)
413- val hardness = ctx .cachedState.getHardness(world, ctx .blockPos)
427+ val blockState = blockState(newCtx .blockPos)
428+ val hardness = newCtx .cachedState.getHardness(world, newCtx .blockPos)
414429
415430 return blockState.isNotEmpty && hardness != 600f && hardness != - 1f
416431 }
@@ -469,7 +484,7 @@ object BreakManager : RequestHandler<BreakRequest>(
469484
470485 val breakInfo = BreakInfo (requestCtx, Primary , request)
471486 primaryBreak?.let { primaryInfo ->
472- if (! breakInfo .breakConfig.doubleBreak || secondaryBreak != null ) {
487+ if (! primaryInfo .breakConfig.doubleBreak || secondaryBreak != null ) {
473488 if (! primaryInfo.updatedThisTick && tickStage in primaryInfo.breakConfig.breakStageMask) {
474489 primaryInfo.cancelBreak()
475490 return @let
0 commit comments