Skip to content

Commit 341acb7

Browse files
committed
fixed issues with break radius / queue. Added onUpdate callback for break requests
1 parent 5fd5a05 commit 341acb7

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ object BreakManager : RequestHandler<BreakRequest>(
315315
.filterNotNull()
316316
.forEach { info ->
317317
newBreaks.find { ctx -> ctx.expectedPos == info.context.expectedPos }?.let { ctx ->
318-
if (!info.updatedThisTick) info.updateInfo(ctx, request)
318+
if (!info.updatedThisTick) {
319+
info.updateInfo(ctx, request)
320+
info.request.onUpdate?.invoke(info.context.expectedPos)
321+
}
319322
newBreaks.remove(ctx)
320323
return@forEach
321324
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ data class BreakRequest(
4141
private val prio: Priority = 0
4242
) : Request(prio, build.breaking) {
4343
var onStart: ((BlockPos) -> Unit)? = null
44+
var onUpdate: ((BlockPos) -> Unit)? = null
4445
var onStop: ((BlockPos) -> Unit)? = null
4546
var onCancel: ((BlockPos) -> Unit)? = null
4647
var onItemDrop: ((ItemEntity) -> Unit)? = null
@@ -66,6 +67,11 @@ data class BreakRequest(
6667
request.onStart = callback
6768
}
6869

70+
@BreakRequestBuilder
71+
fun onUpdate(callback: (BlockPos) -> Unit) {
72+
request.onUpdate = callback
73+
}
74+
6975
@BreakRequestBuilder
7076
fun onStop(callback: (BlockPos) -> Unit) {
7177
request.onStop = callback
@@ -96,6 +102,7 @@ data class BreakRequest(
96102
}
97103

98104
companion object {
105+
@BreakRequestBuilder
99106
fun breakRequest(
100107
contexts: Collection<BreakContext>,
101108
build: BuildConfig,

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import com.lambda.util.world.raycast.InteractionMask
4646
import net.minecraft.util.math.BlockPos
4747
import net.minecraft.util.math.Box
4848
import java.awt.Color
49-
import java.util.*
5049
import java.util.concurrent.ConcurrentLinkedQueue
5150
import kotlin.collections.ArrayList
5251

@@ -105,17 +104,19 @@ object PacketMine : Module(
105104
listen<PlayerEvent.Breaking.Update> { event ->
106105
event.cancel()
107106
val pos = event.pos
108-
val positions = mutableListOf(pos).apply {
109-
if (breakRadius <= 0) return@apply
107+
val positions = mutableListOf<BlockPos>().apply {
108+
if (breakRadius <= 0) {
109+
add(pos)
110+
return@apply
111+
}
110112
BlockPos.iterateOutwards(pos, breakRadius, breakRadius, breakRadius).forEach { blockPos ->
111-
if (blockPos distSq pos <= (breakRadius * breakRadius) && (!flatten || blockPos.y >= player.blockPos.y)) {
113+
if (blockPos distSq pos <= (breakRadius * breakRadius) && (!flatten || (blockPos.y >= player.blockPos.y || blockPos == pos))) {
112114
add(blockPos.toImmutable())
113115
}
114116
}
115117
}
116118
positions.removeIf { breakPos ->
117-
breakPositions.any { it == breakPos }
118-
|| (queue && queuePositions.any { it == pos })
119+
queue && queuePositions.any { it == breakPos }
119120
}
120121
if (positions.isEmpty()) return@listen
121122
val activeBreaking = if (queue) {
@@ -178,6 +179,7 @@ object PacketMine : Module(
178179
}
179180
val request = breakRequest(breakContexts, build, rotation, hotbar, pendingInteractions) {
180181
onStart { queuePositions.removePos(it); addBreak(it) }
182+
onUpdate { queuePositions.removePos(it) }
181183
onStop { removeBreak(it); breaks++ }
182184
onCancel { removeBreak(it, true) }
183185
onReBreakStart { reBreakPos = it }

0 commit comments

Comments
 (0)