@@ -43,7 +43,6 @@ import com.lambda.interaction.request.PositionBlocking
4343import com.lambda.interaction.request.RequestHandler
4444import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode
4545import com.lambda.interaction.request.breaking.BreakConfig.BreakMode
46- import com.lambda.interaction.request.breaking.BreakInfo.BreakType
4746import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary
4847import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak
4948import com.lambda.interaction.request.breaking.BreakInfo.BreakType.RedundantSecondary
@@ -174,7 +173,8 @@ object BreakManager : RequestHandler<BreakRequest>(
174173 listen<TickEvent .Post >(priority = Int .MIN_VALUE ) {
175174 if (! swappedThisTick) {
176175 swappedStack = player.mainHandStack
177- } else swappedThisTick = false
176+ }
177+ swappedThisTick = false
178178 heldTicks++
179179 if (breakCooldown > 0 ) {
180180 breakCooldown--
@@ -189,12 +189,10 @@ object BreakManager : RequestHandler<BreakRequest>(
189189 if (event.pos == RebreakManager .rebreak?.context?.blockPos) return @listen
190190
191191 breakInfos
192- .filterNotNull()
193- .firstOrNull { it.context.blockPos == event.pos }
192+ .firstOrNull { it?.context?.blockPos == event.pos }
194193 ?.let { info ->
195- val currentState = info.context.cachedState
196194 // if not broken
197- if (isNotBroken(currentState , event.newState)) {
195+ if (isNotBroken(info.context.cachedState , event.newState)) {
198196 // update the cached state
199197 info.context.cachedState = event.newState
200198 return @listen
@@ -321,8 +319,7 @@ object BreakManager : RequestHandler<BreakRequest>(
321319
322320 // Reversed so that the breaking order feels natural to the user as the primary break is always the
323321 // last break to be started
324- run {
325- if (! handlePreProcessing()) return @run
322+ if (handlePreProcessing()) {
326323 activeInfos
327324 .filter { it.updatedThisTick }
328325 .asReversed()
@@ -360,15 +357,16 @@ object BreakManager : RequestHandler<BreakRequest>(
360357 .filterNotNull()
361358 .forEach { info ->
362359 newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos && canAccept(ctx) }?.let { ctx ->
363- if (! info.updatedThisTick || info.abandoned) {
364- info.updateInfo(ctx, request)
360+ if ((! info.updatedThisTick || info.type == RedundantSecondary ) || info.abandoned) {
365361 if (info.type == RedundantSecondary )
366362 info.request.onStart?.invoke(info.context.blockPos)
367363 else if (info.abandoned) {
368364 info.abandoned = false
369365 info.request.onStart?.invoke(info.context.blockPos)
370366 } else
371367 info.request.onUpdate?.invoke(info.context.blockPos)
368+
369+ info.updateInfo(ctx, request)
372370 }
373371 newBreaks.remove(ctx)
374372 return @forEach
@@ -417,14 +415,13 @@ object BreakManager : RequestHandler<BreakRequest>(
417415
418416 infos.forEach { it.updatePreProcessing(player, world) }
419417
420- if (swappedThisTick) return true
421-
422418 infos.firstOrNull()?.let { info ->
423- infos.firstOrNull { it.shouldSwap && it.shouldProgress }?.let { last ->
419+ infos.lastOrNull { it.shouldSwap && it.shouldProgress }?.let { last ->
424420 val minSwapTicks = max(info.minSwapTicks, last.minSwapTicks)
425421 if (! info.context.requestSwap(info.request, minSwapTicks))
426422 return false
427- if (minSwapTicks > 0 ) swappedStack = info.swapStack
423+ if (minSwapTicks > 0 )
424+ swappedStack = info.swapStack
428425 }
429426 }
430427 }
@@ -540,7 +537,7 @@ object BreakManager : RequestHandler<BreakRequest>(
540537 .forEach { info ->
541538 if (info.type == RedundantSecondary && ! info.progressedThisTick) {
542539 val cachedState = info.context.cachedState
543- if (cachedState.isEmpty || cachedState.isAir ) {
540+ if (cachedState.isEmpty) {
544541 info.nullify()
545542 return @forEach
546543 }
@@ -675,13 +672,8 @@ object BreakManager : RequestHandler<BreakRequest>(
675672 /* *
676673 * Nullifies the break. If the block is not broken, the [BreakInfo.internalOnCancel] callback gets triggered
677674 */
678- private fun BreakInfo.nullify () = type.nullify()
679-
680- /* *
681- * Nullifies the [BreakInfo] reference in the [breakInfos] array based on the [BreakType]
682- */
683- private fun BreakType.nullify () =
684- when (this ) {
675+ private fun BreakInfo.nullify () =
676+ when (type) {
685677 Primary , Rebreak -> primaryBreak = null
686678 else -> secondaryBreak = null
687679 }
@@ -726,7 +718,7 @@ object BreakManager : RequestHandler<BreakRequest>(
726718 }
727719
728720 val blockState = blockState(ctx.blockPos)
729- if (blockState.isEmpty || blockState.isAir ) {
721+ if (blockState.isEmpty) {
730722 info.nullify()
731723 info.request.onCancel?.invoke(ctx.blockPos)
732724 return false
0 commit comments