@@ -78,7 +78,6 @@ import com.lambda.interaction.material.StackSelection.Companion.select
7878import com.lambda.threading.runGameScheduled
7979import com.lambda.threading.runSafe
8080import com.lambda.threading.runSafeAutomated
81- import com.lambda.util.BlockUtils.blockState
8281import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
8382import com.lambda.util.BlockUtils.isEmpty
8483import com.lambda.util.BlockUtils.isNotBroken
@@ -88,7 +87,6 @@ import com.lambda.util.item.ItemUtils.block
8887import com.lambda.util.math.lerp
8988import com.lambda.util.player.PlayerUtils.gamemode
9089import com.lambda.util.player.PlayerUtils.swingHand
91- import net.minecraft.block.BlockState
9290import net.minecraft.client.sound.PositionedSoundInstance
9391import net.minecraft.client.sound.SoundInstance
9492import net.minecraft.entity.ItemEntity
@@ -181,7 +179,7 @@ object BreakManager : Manager<BreakRequest>(
181179 }
182180
183181 listen<WorldEvent .BlockUpdate .Server >({ Int .MIN_VALUE }) { event ->
184- if (event.pos == RebreakHandler .rebreak ?.context?.blockPos) return @listen
182+ if (event.pos == RebreakHandler .reBreak ?.context?.blockPos) return @listen
185183
186184 breakInfos
187185 .firstOrNull { it?.context?.blockPos == event.pos }
@@ -213,7 +211,7 @@ object BreakManager : Manager<BreakRequest>(
213211 if (entity !is ItemEntity ) return @runGameScheduled
214212
215213 // ToDo: Proper item drop prediction system
216- RebreakHandler .rebreak ?.let { reBreak ->
214+ RebreakHandler .reBreak ?.let { reBreak ->
217215 if (matchesBlockItem(reBreak, entity)) return @runGameScheduled
218216 }
219217
@@ -244,16 +242,11 @@ object BreakManager : Manager<BreakRequest>(
244242 val config = info.breakConfig
245243 if (! config.renders) return @immediateRenderer
246244 val swapMode = config.swapMode
247- val breakDelta = info.request.runSafeAutomated {
248- info.context.cachedState.calcBreakDelta(
249- info.context.blockPos,
250- if (info.type != RedundantSecondary &&
251- swapMode.isEnabled() &&
252- swapMode != BreakConfig .SwapMode .Start
253- ) activeStack
254- else null
255- ).toDouble()
256- }
245+ val breakDelta =
246+ info.request.runSafeAutomated {
247+ val useActiveStack = info.type != RedundantSecondary && swapMode.isEnabled() && swapMode != BreakConfig .SwapMode .Start
248+ info.calcBreakDelta(if (useActiveStack) activeStack else player.mainHandStack).toDouble()
249+ }
257250 val currentDelta = info.breakingTicks * breakDelta
258251
259252 val threshold = if (info.type == Primary ) config.breakThreshold else 1f
@@ -263,18 +256,15 @@ object BreakManager : Manager<BreakRequest>(
263256 val nextTicksProgress = (currentDelta + breakDelta) / adjustedThreshold
264257 val interpolatedProgress = lerp(mc.tickDelta, currentProgress, nextTicksProgress)
265258
266- val fillColor = if (config.dynamicFillColor) lerp(
267- interpolatedProgress,
268- config.startFillColor,
269- config.endFillColor
270- )
271- else config.staticFillColor
272- val outlineColor = if (config.dynamicOutlineColor) lerp(
273- interpolatedProgress,
274- config.startOutlineColor,
275- config.endOutlineColor
276- )
277- else config.staticOutlineColor
259+ val fillColor =
260+ if (config.dynamicFillColor)
261+ lerp(interpolatedProgress, config.startFillColor, config.endFillColor)
262+ else config.staticFillColor
263+
264+ val outlineColor =
265+ if (config.dynamicOutlineColor)
266+ lerp(interpolatedProgress, config.startOutlineColor, config.endOutlineColor)
267+ else config.staticOutlineColor
278268
279269 val pos = info.context.blockPos
280270 info.context.cachedState.getOutlineShape(world, pos).boundingBoxes.map {
@@ -471,9 +461,9 @@ object BreakManager : Manager<BreakRequest>(
471461 request.runSafeAutomated {
472462 if (tickStage !in request.breakConfig.tickStageMask) return false
473463 if (breakDelay > 0 ) return false
464+ if (breaksThisTick >= maxBreaksThisTick) return false
474465
475466 breaks.forEach { ctx ->
476- if (breaksThisTick >= maxBreaksThisTick) return false
477467 if (! currentStackSelection.filterStack(player.inventory.getStack(ctx.hotbarIndex))) return @forEach
478468
479469 initNewBreak(ctx, request) ? : return false
@@ -503,21 +493,32 @@ object BreakManager : Manager<BreakRequest>(
503493 request : BreakRequest
504494 ): BreakInfo ? {
505495 val breakInfo = BreakInfo (requestCtx, Primary , request)
506- primaryBreak?.let { primaryInfo ->
507- if (tickStage !in primaryInfo.breakConfig.tickStageMask) return null
496+ primaryBreak?.let { primary ->
497+ val primaryConfig = primary.breakConfig
498+ if (tickStage !in primaryConfig.tickStageMask) return null
508499 if (! PacketLimitHandler .canSendPackets(1 , PacketType .PlayerAction )) return null
509500
510- if (! primaryInfo.breakConfig .doubleBreak || secondaryBreak != null ) {
511- if (! primaryInfo .updatedThisTick) {
512- primaryInfo .cancelBreak()
501+ if (! primaryConfig .doubleBreak || secondaryBreak != null ) {
502+ if (! primary .updatedThisTick) {
503+ primary .cancelBreak()
513504 return @let
514505 } else return null
515506 }
516507
517- if (! primaryInfo .breaking) return null
508+ if (! primary .breaking) return null
518509
519- secondaryBreak = primaryInfo.apply { type = Secondary }
520- secondaryBreak?.stopBreakPacket()
510+ if (primaryConfig.breakMode == BreakMode .OldGrim ) {
511+ val breakDelta = primary.calcBreakDelta()
512+ val extraTick = ! primary.progressedThisTick
513+ val ticks = primary.breakingTicks.let { if (extraTick) it + 1 else it }
514+ if (ticks * breakDelta >= primaryConfig.breakThreshold) return null
515+ }
516+
517+ secondaryBreak =
518+ primary.apply {
519+ type = Secondary
520+ stopBreakPacket()
521+ }
521522 PacketLimitHandler .sentPackets(1 , PacketType .PlayerAction )
522523 return @let
523524 }
@@ -563,7 +564,7 @@ object BreakManager : Manager<BreakRequest>(
563564 return @forEach
564565 }
565566 info.request.runSafeAutomated {
566- val breakDelta = cachedState .calcBreakDelta(info.context.blockPos, player.mainHandStack )
567+ val breakDelta = info .calcBreakDelta()
567568 val ticksToBreak = 1.0 / breakDelta
568569 val ticksPast = info.breakingTicks - ticksToBreak
569570 if (ticksPast >= 200 ) {
@@ -709,7 +710,7 @@ object BreakManager : Manager<BreakRequest>(
709710 return
710711 }
711712
712- val blockState = blockState( ctx.blockPos)
713+ val blockState = ctx.cachedState
713714 if (blockState.isEmpty) {
714715 info.nullify()
715716 info.request.onCancel?.invoke(this , ctx.blockPos)
@@ -718,15 +719,16 @@ object BreakManager : Manager<BreakRequest>(
718719
719720 if (breakConfig.swapMode == BreakConfig .SwapMode .Constant && ! swapped) return
720721
722+ info.breakingTicks++
723+
721724 val requiresDelayBypassing = info.type == Primary && breakConfig.breakMode == BreakMode .OldGrim && ! info.bypassedDelay
722- if (requiresDelayBypassing && PacketLimitHandler .canSendPackets(22 , PacketType .PlayerAction ) && info.breakingTicks >= 6 ) {
725+ if (requiresDelayBypassing && PacketLimitHandler .canSendPackets(22 , PacketType .PlayerAction ) && info.breakingTicks > 6 ) {
723726 repeat(22 ) { info.startBreakPacket(OLD_GRIM_Y_OFFSET ) }
724727 PacketLimitHandler .sentPackets(22 , PacketType .PlayerAction )
725728 info.bypassedDelay = true
726729 }
727730
728- info.breakingTicks++
729- val breakDelta = blockState.calcBreakDelta(ctx.blockPos)
731+ val breakDelta = info.calcBreakDelta()
730732 val progress = breakDelta * (info.breakingTicks - breakConfig.fudgeFactor)
731733
732734 if (breakConfig.sounds) {
@@ -754,7 +756,7 @@ object BreakManager : Manager<BreakRequest>(
754756 if (info.swapInfo.swap && ! swapped) return
755757
756758 if (info.type == Primary ) {
757- if (breakConfig.breakMode == BreakMode .OldGrim && info.breakingTicks < 6 ) return
759+ if (breakConfig.breakMode == BreakMode .OldGrim && info.breakingTicks <= 6 ) return
758760 if (! PacketLimitHandler .canSendPackets(1 , PacketType .PlayerAction )) return
759761 }
760762
@@ -819,8 +821,7 @@ object BreakManager : Manager<BreakRequest>(
819821 }
820822 if (info.breaking) return false
821823
822- val blockState = blockState(ctx.blockPos)
823- val progress = blockState.calcBreakDelta(ctx.blockPos)
824+ val progress = info.calcBreakDelta()
824825 val instantBreakable = progress >= info.getBreakThreshold()
825826
826827 var packetCount = 1
@@ -840,7 +841,7 @@ object BreakManager : Manager<BreakRequest>(
840841 lastPosStarted = ctx.blockPos
841842
842843 if (info.breakingTicks == 0 ) {
843- blockState .onBlockBreakStart(world, ctx.blockPos, player)
844+ info.context.cachedState .onBlockBreakStart(world, ctx.blockPos, player)
844845 }
845846
846847 if (instantBreakable) onBlockBreak(info)
@@ -871,11 +872,10 @@ object BreakManager : Manager<BreakRequest>(
871872 * Wrapper method for calculating block-breaking delta.
872873 */
873874 context(automatedSafeContext: AutomatedSafeContext )
874- fun BlockState.calcBreakDelta (
875- pos : BlockPos ,
876- item : ItemStack ? = null
875+ fun BreakInfo.calcBreakDelta (
876+ item : ItemStack = automatedSafeContext.player.mainHandStack
877877 ) = with (automatedSafeContext) {
878- val delta = calcItemBlockBreakingDelta( pos , item ? : player.mainHandStack )
878+ val delta = context.cachedState. calcItemBlockBreakingDelta(context.blockPos , item)
879879 // ToDo: This setting requires some fixes / improvements in the player movement prediction to work properly. Currently, it's broken
880880// if (config.desyncFix) {
881881// val nextTickPrediction = buildPlayerPrediction().next()
0 commit comments