Skip to content

Commit c946eca

Browse files
committed
disallow vanilla instant breakables from re-break and cleanup
1 parent 68c8eec commit c946eca

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ data class BreakInfo(
4343
var breakingTicks = 0
4444
var soundsCooldown = 0.0f
4545

46+
var vanillaInstantBreakable = false
47+
val reBreakable get() = !vanillaInstantBreakable && isPrimary
48+
4649
val isPrimary get() = type == BreakType.Primary
4750
val isSecondary get() = type == BreakType.Secondary
4851
val isRedundant get() = type == BreakType.RedundantSecondary
@@ -85,6 +88,12 @@ data class BreakInfo(
8588
}
8689
}
8790

91+
fun tickStats() {
92+
activeAge++
93+
updatedThisTick = false
94+
updatedProgressThisTick = false
95+
}
96+
8897
fun resetCallbacks() {
8998
broken = false
9099
item = null

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ object BreakManager : RequestHandler<BreakRequest>(
121121
this.cancelBreak()
122122
return@apply
123123
}
124-
activeAge++
125-
updatedThisTick = false
126-
updatedProgressThisTick = false
124+
tickStats()
127125
}
128126
}
129127
activeRequest = null
@@ -146,8 +144,8 @@ object BreakManager : RequestHandler<BreakRequest>(
146144
info.internalOnBreak()
147145
if (!info.callbacksCompleted) {
148146
info.startPending()
149-
} else if (info.isPrimary) {
150-
ReBreakManager.startReBreak(info)
147+
} else {
148+
ReBreakManager.offerReBreak(info)
151149
}
152150
info.nullify()
153151
}
@@ -402,8 +400,8 @@ object BreakManager : RequestHandler<BreakRequest>(
402400
info.internalOnBreak()
403401
if (!info.callbacksCompleted) {
404402
info.startPending()
405-
} else if (info.isPrimary) {
406-
ReBreakManager.startReBreak(info)
403+
} else {
404+
ReBreakManager.offerReBreak(info)
407405
}
408406
}
409407
BreakConfirmationMode.BreakThenAwait -> {
@@ -655,8 +653,11 @@ object BreakManager : RequestHandler<BreakRequest>(
655653
if (info.breakConfig.breakMode == BreakMode.Packet) {
656654
info.stopBreakPacket(world, interaction)
657655
}
656+
658657
info.startBreakPacket(world, interaction)
659-
if (info.isSecondary || (breakDelta < 1 && breakDelta >= info.breakConfig.breakThreshold)) {
658+
info.vanillaInstantBreakable = breakDelta >= 1
659+
660+
if (info.isSecondary || (!info.vanillaInstantBreakable && breakDelta >= info.breakConfig.breakThreshold)) {
660661
info.stopBreakPacket(world, interaction)
661662
}
662663

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object BrokenBlockHandler {
9292
if (pending.callbacksCompleted) {
9393
pending.stopPending()
9494
if (lastPosStarted == pending.context.expectedPos) {
95-
ReBreakManager.startReBreak(pending)
95+
ReBreakManager.offerReBreak(pending)
9696
}
9797
}
9898
return@listen
@@ -112,7 +112,7 @@ object BrokenBlockHandler {
112112
if (pending.callbacksCompleted) {
113113
pending.stopPending()
114114
if (lastPosStarted == pending.context.expectedPos) {
115-
ReBreakManager.startReBreak(pending)
115+
ReBreakManager.offerReBreak(pending)
116116
}
117117
}
118118
return@listen

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object ReBreakManager {
3636
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
3737
reBreak?.apply {
3838
breakingTicks++
39-
activeAge++
39+
tickStats()
4040
}
4141
}
4242

@@ -45,8 +45,10 @@ object ReBreakManager {
4545
}
4646
}
4747

48-
fun startReBreak(info: BreakInfo?) {
49-
reBreak = info?.apply {
48+
fun offerReBreak(info: BreakInfo) {
49+
if (!info.reBreakable) return
50+
51+
reBreak = info.apply {
5052
type = BreakType.ReBreak
5153
breaking = true
5254
}
@@ -63,8 +65,7 @@ object ReBreakManager {
6365
if (info.context.expectedPos != ctx.expectedPos || info.breakConfig.reBreak.mode != ReBreakSettings.Mode.Manual) {
6466
return@runSafe ReBreakResult.Ignored
6567
}
66-
info.context = ctx
67-
info.request = breakRequest
68+
info.updateInfo(ctx, breakRequest)
6869

6970
val context = info.context
7071
val awaitThenBreak = info.breakConfig.breakConfirmation == BreakConfig.BreakConfirmationMode.AwaitThenBreak

0 commit comments

Comments
 (0)