Skip to content

Commit 3515c29

Browse files
committed
redundancy improvements
1 parent 7ac8925 commit 3515c29

File tree

2 files changed

+33
-40
lines changed

2 files changed

+33
-40
lines changed

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

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ object BreakManager : RequestHandler<BreakRequest>(
107107
val currentStackSelection
108108
get() = breakInfos
109109
.lastOrNull {
110-
it?.breakConfig?.doubleBreak == true || it?.isSecondary == true
110+
it?.isRedundant == false && (it.breakConfig.doubleBreak || it.isSecondary)
111111
}?.context?.itemSelection
112112
?: StackSelection.EVERYTHING.select()
113113

@@ -172,6 +172,10 @@ object BreakManager : RequestHandler<BreakRequest>(
172172
return@listen
173173
}
174174
destroyBlock(info)
175+
if (info.isRedundant) {
176+
info.nullify()
177+
return@listen
178+
}
175179
info.request.onStop?.invoke(info.context.blockPos)
176180
info.internalOnBreak()
177181
if (info.callbacksCompleted)
@@ -185,6 +189,7 @@ object BreakManager : RequestHandler<BreakRequest>(
185189
listen<EntityEvent.Update>(priority = Int.MIN_VALUE) {
186190
if (it.entity !is ItemEntity) return@listen
187191

192+
// ToDo: Proper item drop prediction system
188193
ReBreakManager.reBreak?.let { reBreak ->
189194
if (matchesBlockItem(reBreak, it.entity)) return@listen
190195
}
@@ -364,7 +369,15 @@ object BreakManager : RequestHandler<BreakRequest>(
364369
.asSequence()
365370
.filter { !it.updatedThisTick && tickStage in it.breakConfig.breakStageMask }
366371
.forEach { info ->
367-
if (info.isRedundant && !info.progressedThisTick) updateBreakProgress(info)
372+
if (info.isRedundant && !info.progressedThisTick) {
373+
val cachedState = info.context.cachedState
374+
if (cachedState.isEmpty || cachedState.isAir) {
375+
info.nullify()
376+
return@forEach
377+
}
378+
info.progressedThisTick = true
379+
info.breakingTicks++
380+
}
368381
else info.cancelBreak()
369382
}
370383
}
@@ -422,12 +435,8 @@ object BreakManager : RequestHandler<BreakRequest>(
422435
private fun SafeContext.canAccept(newCtx: BreakContext): Boolean {
423436
if (breakInfos.none { it?.context?.blockPos == newCtx.blockPos } && isPosBlocked(newCtx.blockPos)) return false
424437

425-
breakInfos
426-
.lastOrNull { it != null && !it.isRedundant && it.breakConfig.doubleBreak }
427-
?.let { current ->
428-
val newStack = player.inventory.getStack(newCtx.hotbarIndex)
429-
if (!current.context.itemSelection.filterStack(newStack)) return false
430-
}
438+
if (!currentStackSelection.filterStack(player.inventory.getStack(newCtx.hotbarIndex)))
439+
return false
431440

432441
val blockState = blockState(newCtx.blockPos)
433442
val hardness = newCtx.cachedState.getHardness(world, newCtx.blockPos)
@@ -536,29 +545,25 @@ object BreakManager : RequestHandler<BreakRequest>(
536545
*/
537546
private fun SafeContext.onBlockBreak(info: BreakInfo) {
538547
info.request.onStop?.invoke(info.context.blockPos)
539-
if (info.isRedundant) {
540-
info.startPending()
541-
} else {
542-
when (info.breakConfig.breakConfirmation) {
543-
BreakConfirmationMode.None -> {
544-
destroyBlock(info)
545-
info.internalOnBreak()
546-
if (!info.callbacksCompleted) {
547-
info.startPending()
548-
} else {
549-
ReBreakManager.offerReBreak(info)
550-
}
551-
}
552-
BreakConfirmationMode.BreakThenAwait -> {
553-
destroyBlock(info)
554-
info.startPending()
555-
}
556-
BreakConfirmationMode.AwaitThenBreak -> {
548+
when (info.breakConfig.breakConfirmation) {
549+
BreakConfirmationMode.None -> {
550+
destroyBlock(info)
551+
info.internalOnBreak()
552+
if (!info.callbacksCompleted) {
557553
info.startPending()
554+
} else {
555+
ReBreakManager.offerReBreak(info)
558556
}
559557
}
560-
breaksThisTick++
558+
BreakConfirmationMode.BreakThenAwait -> {
559+
destroyBlock(info)
560+
info.startPending()
561+
}
562+
BreakConfirmationMode.AwaitThenBreak -> {
563+
info.startPending()
564+
}
561565
}
566+
breaksThisTick++
562567
info.nullify()
563568
}
564569

@@ -632,10 +637,6 @@ object BreakManager : RequestHandler<BreakRequest>(
632637
val hitResult = ctx.result
633638

634639
if (gamemode.isCreative && world.worldBorder.contains(ctx.blockPos) && info.breaking) {
635-
if (info.isRedundant) {
636-
onBlockBreak(info)
637-
return true
638-
}
639640
breakCooldown = config.breakDelay
640641
lastPosStarted = ctx.blockPos
641642
onBlockBreak(info)
@@ -682,7 +683,7 @@ object BreakManager : RequestHandler<BreakRequest>(
682683
val blockState = blockState(ctx.blockPos)
683684
if (blockState.isEmpty || blockState.isAir) {
684685
info.nullify()
685-
if (!info.isRedundant) info.request.onCancel?.invoke(info.context.blockPos)
686+
info.request.onCancel?.invoke(info.context.blockPos)
686687
return false
687688
}
688689

@@ -696,13 +697,6 @@ object BreakManager : RequestHandler<BreakRequest>(
696697

697698
val overBreakThreshold = progress >= info.getBreakThreshold()
698699

699-
if (info.isRedundant) {
700-
if (overBreakThreshold) {
701-
onBlockBreak(info)
702-
}
703-
return true
704-
}
705-
706700
if (config.sounds) {
707701
if (info.soundsCooldown % 4.0f == 0.0f) {
708702
val blockSoundGroup = blockState.soundGroup

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ object BrokenBlockHandler : PostActionHandler<BreakInfo>() {
9393
}
9494

9595
if (pending.breakConfig.breakConfirmation == BreakConfirmationMode.AwaitThenBreak
96-
|| pending.isRedundant
9796
|| (pending.isReBreaking && !pending.breakConfig.reBreak)
9897
) {
9998
destroyBlock(pending)

0 commit comments

Comments
 (0)