Skip to content

Commit 1b60759

Browse files
committed
fixed instability issue at slower rotation speeds when using a higher break radius in packetmine and renamed / moved onAccept and onBreak to onStart and onStop to and are now called when starting and stopping breaking a block.
1 parent 11147d2 commit 1b60759

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

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

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

46-
var pending = false
47-
4846
var vanillaInstantBreakable = false
4947
val reBreakable get() = !vanillaInstantBreakable && isPrimary
5048

@@ -63,7 +61,6 @@ data class BreakInfo(
6361
@Synchronized
6462
fun internalOnBreak() {
6563
if (!isReBreaking) broken = true
66-
request.onBreak?.invoke(context.expectedPos)
6764
item?.let { item ->
6865
request.onItemDrop?.invoke(item)
6966
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ object BreakManager : RequestHandler<BreakRequest>(
255255
private fun SafeContext.populateFrom(request: BreakRequest) {
256256
// Sanitize the new breaks
257257
val newBreaks = request.contexts
258+
.distinctBy { it.expectedPos }
258259
.filter { ctx -> canAccept(ctx, request.build.breaking) }
259260
.toMutableList()
260261

@@ -316,7 +317,6 @@ object BreakManager : RequestHandler<BreakRequest>(
316317
if (!rotated || tickStage !in request.build.breaking.breakStageMask) return false
317318

318319
val breakInfo = initNewBreak(ctx, request) ?: return false
319-
request.onAccept?.invoke(ctx.expectedPos)
320320
updateBreakProgress(breakInfo)
321321
breaksThisTick++
322322
iterator.remove()
@@ -337,7 +337,6 @@ object BreakManager : RequestHandler<BreakRequest>(
337337
while (iterator.hasNext()) {
338338
val ctx = iterator.next()
339339
initNewBreak(ctx, request) ?: return false
340-
request.onAccept?.invoke(ctx.expectedPos)
341340
iterator.remove()
342341
if (atMaxBreakInfos(request.build.breaking)) return false
343342
}
@@ -404,6 +403,7 @@ object BreakManager : RequestHandler<BreakRequest>(
404403
* @see startPending
405404
*/
406405
private fun SafeContext.onBlockBreak(info: BreakInfo) {
406+
info.request.onStop?.invoke(info.context.expectedPos)
407407
when (info.breakConfig.breakConfirmation) {
408408
BreakConfirmationMode.None -> {
409409
destroyBlock(info)
@@ -520,7 +520,7 @@ object BreakManager : RequestHandler<BreakRequest>(
520520
primaryBreak = reBreakResult.breakInfo.apply {
521521
type = Primary
522522
ReBreakManager.clearReBreak()
523-
request.onAccept?.invoke(ctx.expectedPos)
523+
request.onStart?.invoke(ctx.expectedPos)
524524
}
525525

526526
return primaryBreak?.let { primary ->
@@ -631,13 +631,15 @@ object BreakManager : RequestHandler<BreakRequest>(
631631
if (gamemode.isCreative) {
632632
lastPosStarted = ctx.expectedPos
633633
onBlockBreak(info)
634+
info.request.onStart?.invoke(ctx.expectedPos)
634635
interaction.sendSequencedPacket(world) { sequence: Int ->
635636
PlayerActionC2SPacket(Action.START_DESTROY_BLOCK, ctx.expectedPos, ctx.result.side, sequence)
636637
}
637638
breakCooldown = info.breakConfig.breakDelay
638639
return true
639640
}
640641
if (info.breaking) return false
642+
info.request.onStart?.invoke(ctx.expectedPos)
641643

642644
lastPosStarted = ctx.expectedPos
643645

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ data class BreakRequest(
3535
val rotation: RotationConfig,
3636
val hotbar: HotbarConfig,
3737
val pendingInteractions: MutableCollection<BuildContext>,
38-
val onAccept: ((BlockPos) -> Unit)? = null,
38+
val onStart: ((BlockPos) -> Unit)? = null,
39+
val onStop: ((BlockPos) -> Unit)? = null,
3940
val onCancel: ((BlockPos) -> Unit)? = null,
40-
val onBreak: ((BlockPos) -> Unit)? = null,
4141
val onItemDrop: ((ItemEntity) -> Unit)? = null,
4242
val onReBreakStart: ((BlockPos) -> Unit)? = null,
4343
val onReBreak: ((BlockPos) -> Unit)? = null,

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
@@ -131,7 +131,6 @@ object BrokenBlockHandler {
131131
* Adds the [info] to the [BrokenBlockHandler], and requesters, pending interaction collections.
132132
*/
133133
fun BreakInfo.startPending() {
134-
pending = true
135134
pendingBreaks.add(this)
136135
pendingInteractions.add(context)
137136
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ object PacketMine : Module(
104104
}
105105
}
106106
positions.removeIf { breakPos ->
107-
breakPositions.any { it == breakPos }
107+
breakPositions.any { it == breakPos } || queuePositions.any { it == pos }
108108
}
109109
if (positions.isEmpty()) return@listen
110110
val activeBreaking = if (queue) {
@@ -142,9 +142,9 @@ object PacketMine : Module(
142142
}
143143
val request = BreakRequest(
144144
breakContexts, build, rotation, hotbar, pendingInteractions = pendingInteractionsList,
145-
onAccept = { queuePositions.removePos(it); addBreak(it) },
145+
onStart = { queuePositions.removePos(it); addBreak(it) },
146+
onStop = { removeBreak(it); breaks++ },
146147
onCancel = { removeBreak(it, true) },
147-
onBreak = { removeBreak(it); breaks++ },
148148
onReBreakStart = { reBreakPos = it },
149149
onReBreak = { reBreakPos = it },
150150
onItemDrop = { _ -> itemDrops++ }
@@ -202,6 +202,12 @@ object PacketMine : Module(
202202
return modified
203203
}
204204

205+
private fun LinkedHashSet<MutableCollection<BlockPos>>.any(predicate: (BlockPos) -> Boolean): Boolean {
206+
if (isEmpty()) return false
207+
forEach { if (it.any(predicate)) return true }
208+
return false
209+
}
210+
205211
enum class Page {
206212
Build, Rotation, Interaction, Inventory, Hotbar
207213
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class BuildTask @Ta5kBuilder constructor(
157157
val request = BreakRequest(
158158
requestContexts, build, rotation, hotbar,
159159
pendingInteractions = pendingInteractions,
160-
onBreak = { breaks++ },
160+
onStop = { breaks++ },
161161
onItemDrop = onItemDrop
162162
)
163163
build.breaking.request(request)

0 commit comments

Comments
 (0)