@@ -67,6 +67,7 @@ import com.lambda.interaction.request.breaking.BrokenBlockHandler.pendingActions
6767import com.lambda.interaction.request.breaking.BrokenBlockHandler.setPendingConfigs
6868import com.lambda.interaction.request.breaking.BrokenBlockHandler.startPending
6969import com.lambda.interaction.request.breaking.SwapInfo.Companion.getSwapInfo
70+ import com.lambda.interaction.request.hotbar.HotbarRequest
7071import com.lambda.interaction.request.interacting.InteractionManager
7172import com.lambda.interaction.request.placing.PlaceManager
7273import com.lambda.interaction.request.rotating.RotationRequest
@@ -319,6 +320,7 @@ object BreakManager : RequestHandler<BreakRequest>(
319320 */
320321 private fun SafeContext.processRequest (breakRequest : BreakRequest ? ) {
321322 breakRequest?.let { request ->
323+ logger.debug(" Processing request (${request.requestID} ) at tick stage ${tickStage?.run { this ::class .qualifiedName }} " )
322324 if (request.fresh) populateFrom(request)
323325 }
324326
@@ -343,6 +345,7 @@ object BreakManager : RequestHandler<BreakRequest>(
343345 }
344346
345347 if (instantBreaks.isEmpty() && breaks.isEmpty()) {
348+ if (activeRequest != null ) logger.debug(" Clearing active request" )
346349 activeRequest = null
347350 }
348351 if (breaksThisTick > 0 || activeInfos.isNotEmpty()) {
@@ -359,6 +362,8 @@ object BreakManager : RequestHandler<BreakRequest>(
359362 * @see canAccept
360363 */
361364 private fun SafeContext.populateFrom (request : BreakRequest ) {
365+ logger.debug(" Populating from request (${request.requestID} )" )
366+
362367 // Sanitize the new breaks
363368 val newBreaks = request.contexts
364369 .distinctBy { it.blockPos }
@@ -370,6 +375,7 @@ object BreakManager : RequestHandler<BreakRequest>(
370375 .forEach { info ->
371376 newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos && canAccept(ctx) }?.let { ctx ->
372377 if ((! info.updatedThisTick || info.type == RedundantSecondary ) || info.abandoned) {
378+ logger.debug(" Updating info for ${info.type} " )
373379 if (info.type == RedundantSecondary )
374380 info.request.onStart?.invoke(info.context.blockPos)
375381 else if (info.abandoned) {
@@ -389,10 +395,14 @@ object BreakManager : RequestHandler<BreakRequest>(
389395 .filter { it.instantBreak }
390396 .toMutableList()
391397
398+ logger.debug(" ${instantBreaks.size} unprocessed instant breaks" )
399+
392400 breaks = newBreaks
393401 .filter { ! it.instantBreak }
394402 .toMutableList()
395403
404+ logger.debug(" ${breaks.size} unprocessed instant breaks" )
405+
396406 val breakConfig = request.config
397407 val pendingLimit = (breakConfig.maxPendingBreaks - pendingBreakCount).coerceAtLeast(0 )
398408 maxBreaksThisTick = breakConfig.breaksPerTick.coerceAtMost(pendingLimit)
@@ -417,9 +427,11 @@ object BreakManager : RequestHandler<BreakRequest>(
417427 activeInfos
418428 .filter { it.updatedThisTick }
419429 .let { infos ->
430+ if (infos.isNotEmpty()) logger.debug(" Handling pre-processing" )
420431 rotationRequest = infos.firstOrNull { info -> info.breakConfig.rotateForBreak }
421432 ?.let { info ->
422433 val rotation = info.context.rotation
434+ logger.debug(" Requesting rotation (${rotation.requestID} )" )
423435 rotation.submit(false )
424436 }
425437
@@ -430,8 +442,18 @@ object BreakManager : RequestHandler<BreakRequest>(
430442 infos.firstOrNull()?.let { info ->
431443 infos.lastOrNull { it.swapInfo.swap && it.shouldProgress }?.let { last ->
432444 val minSwapTicks = max(info.swapInfo.minKeepTicks, last.swapInfo.minKeepTicks)
433- if (! info.context.requestSwap(info.request, minSwapTicks))
445+ val hotbarRequest = with (info) {
446+ HotbarRequest (
447+ context.hotbarIndex,
448+ request.hotbar,
449+ request.hotbar.keepTicks.coerceAtLeast(minSwapTicks)
450+ ).submit(false )
451+ }
452+ logger.debug(" Submitting request for hotbar index ${info.context.hotbarIndex} with min swap ticks $minSwapTicks (${hotbarRequest.requestID} )" )
453+ if (! hotbarRequest.done) {
454+ logger.debug(" hotbar request failed (${hotbarRequest.requestID} )" )
434455 return false
456+ }
435457 if (minSwapTicks > 0 ) {
436458 val alreadySwapped = swappedThisTick
437459 currentStack = info.swapStack
@@ -450,6 +472,7 @@ object BreakManager : RequestHandler<BreakRequest>(
450472 * @return false if a break could not be performed.
451473 */
452474 private fun SafeContext.performInstantBreaks (request : BreakRequest ): Boolean {
475+ if (instantBreaks.isNotEmpty()) logger.debug(" Processing instant breaks" )
453476 val iterator = instantBreaks.iterator()
454477 while (iterator.hasNext()) {
455478 if (breaksThisTick + 1 > maxBreaksThisTick) return false
@@ -478,6 +501,7 @@ object BreakManager : RequestHandler<BreakRequest>(
478501 * @see initNewBreak
479502 */
480503 private fun SafeContext.processNewBreaks (request : BreakRequest ): Boolean {
504+ if (breaks.isNotEmpty()) logger.debug(" Processing new breaks" )
481505 val iterator = breaks.iterator()
482506 while (iterator.hasNext()) {
483507 val ctx = iterator.next()
@@ -515,8 +539,9 @@ object BreakManager : RequestHandler<BreakRequest>(
515539 return secondaryBreak
516540 }
517541
542+ logger.debug(" Transforming ${primaryInfo.type} to $Secondary " )
518543 primaryInfo.stopBreakPacket(world, interaction)
519- primaryInfo.makeSecondary()
544+ secondaryBreak = primaryInfo.apply { type = Secondary }
520545 return @let
521546 }
522547
@@ -605,6 +630,8 @@ object BreakManager : RequestHandler<BreakRequest>(
605630 }
606631
607632 private fun BreakInfo.updatePreProcessing (player : ClientPlayerEntity , world : BlockView ) {
633+ logger.debug(" Updating pre-processing for $type " )
634+
608635 shouldProgress = ! progressedThisTick
609636 && tickStage in breakConfig.breakStageMask
610637 && (rotated || type != Primary )
@@ -617,17 +644,6 @@ object BreakManager : RequestHandler<BreakRequest>(
617644 swapInfo = getSwapInfo(this , player, world)
618645 }
619646
620- /* *
621- * Makes the [BreakInfo] a secondary if not already.
622- */
623- private fun BreakInfo.makeSecondary () {
624- if (secondaryBreak == = this ) return
625- secondaryBreak = this .apply {
626- type = Secondary
627- }
628- primaryBreak = null
629- }
630-
631647 /* *
632648 * Attempts to cancel the break.
633649 *
@@ -643,17 +659,20 @@ object BreakManager : RequestHandler<BreakRequest>(
643659 if (type == RedundantSecondary || abandoned) return @runSafe
644660 when (type) {
645661 Primary -> {
662+ logger.debug(" Cancelling $type " )
646663 nullify()
647664 setBreakingTextureStage(player, world, - 1 )
648665 abortBreakPacket(world, interaction)
649666 request.onCancel?.invoke(context.blockPos)
650667 }
651668 Secondary -> {
652669 if (breakConfig.unsafeCancels) {
670+ logger.warning(" Making $type redundant" )
653671 type = RedundantSecondary
654672 setBreakingTextureStage(player, world, - 1 )
655673 request.onCancel?.invoke(context.blockPos)
656674 } else {
675+ logger.debug(" Abandoning $type " )
657676 abandoned = true
658677 }
659678 }
@@ -713,6 +732,7 @@ object BreakManager : RequestHandler<BreakRequest>(
713732 if (blockState.isEmpty) {
714733 info.nullify()
715734 info.request.onCancel?.invoke(ctx.blockPos)
735+ logger.warning(" Block state was unexpectedly empty" )
716736 return false
717737 }
718738
@@ -723,6 +743,7 @@ object BreakManager : RequestHandler<BreakRequest>(
723743 ctx.blockPos,
724744 config
725745 ) * (info.breakingTicks - config.fudgeFactor)
746+ logger.debug(" ${info.type} progress: $progress , breaking ticks: ${info.breakingTicks} " )
726747
727748 if (config.sounds) {
728749 if (info.soundsCooldown % 4.0f == 0.0f ) {
@@ -751,6 +772,7 @@ object BreakManager : RequestHandler<BreakRequest>(
751772
752773 val swing = config.swing
753774 if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) {
775+ logger.success(" Breaking ${info.type} " )
754776 if (info.type == Primary ) {
755777 onBlockBreak(info)
756778 info.stopBreakPacket(world, interaction)
@@ -777,8 +799,10 @@ object BreakManager : RequestHandler<BreakRequest>(
777799 val ctx = info.context
778800
779801 if (info.rebreakPotential.isPossible()) {
802+ logger.debug(" Handling potential rebreak" )
780803 when (val rebreakResult = RebreakHandler .handleUpdate(info.context, info.request)) {
781804 is RebreakResult .StillBreaking -> {
805+ logger.debug(" Rebreak not complete" )
782806 primaryBreak = rebreakResult.breakInfo.apply {
783807 type = Primary
784808 RebreakHandler .clearRebreak()
@@ -792,6 +816,7 @@ object BreakManager : RequestHandler<BreakRequest>(
792816 return true
793817 }
794818 is RebreakResult .Rebroke -> {
819+ logger.debug(" Rebroke" )
795820 info.type = Rebreak
796821 info.nullify()
797822 info.request.onReBreak?.invoke(ctx.blockPos)
@@ -825,9 +850,11 @@ object BreakManager : RequestHandler<BreakRequest>(
825850 val progress = blockState.calcBreakDelta(player, world, ctx.blockPos, info.breakConfig)
826851 info.vanillaInstantBreakable = progress >= 1 && info.swapInfo.canCompleteBreak
827852 if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) {
853+ logger.success(" Instantly breaking" )
828854 onBlockBreak(info)
829855 if (! info.vanillaInstantBreakable) breakCooldown = info.breakConfig.breakDelay
830856 } else {
857+ logger.debug(" Starting ${info.type} " )
831858 info.apply {
832859 breaking = true
833860 breakingTicks = 1
0 commit comments