Skip to content

Commit 1f63a8b

Browse files
committed
fixe for when unsafe cancels is disabled, and improvements for reviving abandoned and redundant break infos
1 parent 97c60d2 commit 1f63a8b

File tree

6 files changed

+72
-23
lines changed

6 files changed

+72
-23
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ data class BreakInfo(
4040
var updatedProgressThisTick = false
4141

4242
var breaking = false
43+
var abandoned = false
4344
var breakingTicks = 0
4445
var soundsCooldown = 0.0f
4546

@@ -78,13 +79,10 @@ data class BreakInfo(
7879
request.onCancel?.invoke(context.blockPos)
7980
}
8081

81-
fun updateInfo(context: BreakContext, request: BreakRequest) {
82+
fun updateInfo(context: BreakContext, request: BreakRequest? = null) {
8283
updatedThisTick = true
8384
this.context = context
84-
this.request = request
85-
if (isRedundant) {
86-
type = BreakType.Secondary
87-
}
85+
request?.let { this.request = it }
8886
}
8987

9088
fun tickStats() {

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ import com.lambda.event.listener.SafeListener.Companion.listen
3030
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
3131
import com.lambda.graphics.renderer.esp.builders.buildFilled
3232
import com.lambda.graphics.renderer.esp.builders.buildOutline
33+
import com.lambda.interaction.construction.blueprint.Blueprint.Companion.toStructure
34+
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
3335
import com.lambda.interaction.construction.context.BreakContext
3436
import com.lambda.interaction.construction.processing.ProcessorRegistry
37+
import com.lambda.interaction.construction.result.BreakResult
38+
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
39+
import com.lambda.interaction.construction.verify.TargetState
3540
import com.lambda.interaction.request.ManagerUtils.isPosBlocked
3641
import com.lambda.interaction.request.PositionBlocking
3742
import com.lambda.interaction.request.Priority
@@ -126,6 +131,28 @@ object BreakManager : RequestHandler<BreakRequest>(
126131
override fun load(): String {
127132
super.load()
128133

134+
listen<TickEvent.Pre>(priority = Int.MIN_VALUE) {
135+
// Cancelled but double breaking so requires break manager to continue the simulation
136+
breakInfos
137+
.asSequence()
138+
.filterNotNull()
139+
.filter { it.abandoned && !it.isRedundant }
140+
.forEach { info ->
141+
with (info.request) {
142+
info.context.blockPos
143+
.toStructure(TargetState.Empty)
144+
.toBlueprint()
145+
.simulate(player.eyePos, interact, rotation, inventory, build)
146+
.asSequence()
147+
.filterIsInstance<BreakResult.Break>()
148+
.sorted()
149+
.let { sim ->
150+
info.updateInfo(sim.firstOrNull()?.context ?: return@forEach)
151+
}
152+
}
153+
}
154+
}
155+
129156
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
130157
if (breakCooldown > 0) {
131158
breakCooldown--
@@ -200,7 +227,7 @@ object BreakManager : RequestHandler<BreakRequest>(
200227
world,
201228
info.context.blockPos,
202229
info.breakConfig,
203-
player.inventory.getStack(info.context.hotbarIndex)
230+
if (!info.isRedundant) player.inventory.getStack(info.context.hotbarIndex) else null
204231
)
205232
val progress = (info.breakingTicks * breakDelta).let {
206233
if (info.isPrimary) it * (2 - info.breakConfig.breakThreshold)
@@ -337,9 +364,17 @@ object BreakManager : RequestHandler<BreakRequest>(
337364
.filterNotNull()
338365
.forEach { info ->
339366
newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos }?.let { ctx ->
340-
if (!info.updatedThisTick) {
367+
if (!info.updatedThisTick || info.abandoned) {
341368
info.updateInfo(ctx, request)
342-
info.request.onUpdate?.invoke(info.context.blockPos)
369+
if (info.isRedundant) {
370+
info.type = BreakType.Secondary
371+
info.request.onStart?.invoke(info.context.blockPos)
372+
} else if (info.abandoned) {
373+
info.abandoned = false
374+
info.request.onStart?.invoke(info.context.blockPos)
375+
} else {
376+
info.request.onUpdate?.invoke(info.context.blockPos)
377+
}
343378
}
344379
newBreaks.remove(ctx)
345380
return@forEach
@@ -530,8 +565,9 @@ object BreakManager : RequestHandler<BreakRequest>(
530565
if (isPrimary) {
531566
if (breaking) abortBreakPacket(world, interaction)
532567
nullify()
533-
} else if (isSecondary && breakConfig.unsafeCancels) {
534-
makeRedundant()
568+
} else if (isSecondary) {
569+
if (breakConfig.unsafeCancels) makeRedundant()
570+
else abandoned = true
535571
}
536572

537573
internalOnCancel()
@@ -755,7 +791,7 @@ object BreakManager : RequestHandler<BreakRequest>(
755791
item: ItemStack? = null
756792
) = runSafe {
757793
var delta = calcItemBlockBreakingDelta(player, world, pos, item ?: player.inventory.mainHandStack)
758-
// This setting requires some fixes / improvements in the player movement prediction to work properly. Currently, its broken
794+
//ToDo: This setting requires some fixes / improvements in the player movement prediction to work properly. Currently, it's broken
759795
if (config.desyncFix) {
760796
val nextTickPrediction = buildPlayerPrediction().next()
761797
if (player.isOnGround && !nextTickPrediction.onGround) {

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package com.lambda.interaction.request.breaking
1919

2020
import com.lambda.config.groups.BuildConfig
21+
import com.lambda.config.groups.InteractionConfig
22+
import com.lambda.config.groups.InventoryConfig
2123
import com.lambda.interaction.construction.context.BreakContext
2224
import com.lambda.interaction.construction.context.BuildContext
2325
import com.lambda.interaction.request.Request
@@ -34,10 +36,12 @@ annotation class BreakRequestBuilder
3436

3537
data class BreakRequest(
3638
val contexts: Collection<BreakContext>,
37-
val build: BuildConfig,
38-
val rotation: RotationConfig,
39+
val pendingInteractions: MutableCollection<BuildContext>,
3940
val hotbar: HotbarConfig,
40-
val pendingInteractions: MutableCollection<BuildContext>
41+
val rotation: RotationConfig,
42+
val inventory: InventoryConfig,
43+
val interact: InteractionConfig,
44+
val build: BuildConfig
4145
) : Request(build.breaking) {
4246
var onStart: ((BlockPos) -> Unit)? = null
4347
var onUpdate: ((BlockPos) -> Unit)? = null
@@ -53,12 +57,14 @@ data class BreakRequest(
5357
@BreakRequestBuilder
5458
class RequestBuilder(
5559
contexts: Collection<BreakContext>,
56-
build: BuildConfig,
60+
pendingInteractions: MutableCollection<BuildContext>,
5761
rotation: RotationConfig,
5862
hotbar: HotbarConfig,
59-
pendingInteractions: MutableCollection<BuildContext>
63+
interact: InteractionConfig,
64+
inventory: InventoryConfig,
65+
build: BuildConfig
6066
) {
61-
val request = BreakRequest(contexts, build, rotation, hotbar, pendingInteractions)
67+
val request = BreakRequest(contexts, pendingInteractions, hotbar, rotation, inventory, interact, build)
6268

6369
@BreakRequestBuilder
6470
fun onStart(callback: (BlockPos) -> Unit) {
@@ -103,11 +109,13 @@ data class BreakRequest(
103109
@BreakRequestBuilder
104110
fun breakRequest(
105111
contexts: Collection<BreakContext>,
106-
build: BuildConfig,
112+
pendingInteractions: MutableCollection<BuildContext>,
107113
rotation: RotationConfig,
108114
hotbar: HotbarConfig,
109-
pendingInteractions: MutableCollection<BuildContext>,
115+
interact: InteractionConfig,
116+
inventory: InventoryConfig,
117+
build: BuildConfig,
110118
builder: RequestBuilder.() -> Unit
111-
) = RequestBuilder(contexts, build, rotation, hotbar, pendingInteractions).apply(builder).build()
119+
) = RequestBuilder(contexts, pendingInteractions, rotation, hotbar, interact, inventory, build).apply(builder).build()
112120
}
113121
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ object BrokenBlockHandler {
9292
return@listen
9393
}
9494

95-
if (pending.breakConfig.breakConfirmation == BreakConfirmationMode.AwaitThenBreak || pending.isRedundant) {
95+
if (pending.breakConfig.breakConfirmation == BreakConfirmationMode.AwaitThenBreak
96+
|| pending.isRedundant
97+
|| (pending.isReBreaking && !pending.breakConfig.reBreak)
98+
) {
9699
destroyBlock(pending)
97100
}
98101
pending.internalOnBreak()

common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ object PacketMine : Module(
176176
if (!reBreaking) {
177177
queuePositions.retainAllPositions(breakContexts)
178178
}
179-
val request = breakRequest(breakContexts, build, rotation, hotbar, pendingInteractions) {
179+
val request = breakRequest(
180+
breakContexts, pendingInteractions, rotation, hotbar, interact, inventory, build,
181+
) {
180182
onStart { queuePositions.removePos(it); addBreak(it) }
181183
onUpdate { queuePositions.removePos(it) }
182184
onStop { removeBreak(it); breaks++ }

common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ class BuildTask @Ta5kBuilder constructor(
156156
requestContexts.addAll(breakResults.map { it.context })
157157
}
158158

159-
val request = breakRequest(requestContexts, build, rotation, hotbar, pendingInteractions) {
159+
val request = breakRequest(
160+
requestContexts, pendingInteractions, rotation, hotbar, interact, inventory, build,
161+
) {
160162
onStop { breaks++ }
161163
onItemDrop?.let { onItemDrop ->
162164
onItemDrop { onItemDrop(it) }

0 commit comments

Comments
 (0)