Skip to content

Commit 7ac8925

Browse files
committed
more details in break info warnings and allow any block as long as it matches the current breaking stack selection
1 parent 2f28e0a commit 7ac8925

File tree

4 files changed

+32
-33
lines changed

4 files changed

+32
-33
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -795,15 +795,7 @@ object BuildSimulator {
795795
val swapStack = swapCandidates.map { it.matchingStacks(stackSelection) }
796796
.asSequence()
797797
.flatten()
798-
.filter { newStack ->
799-
BreakManager.currentStackSelection.filterStack(newStack) &&
800-
BreakManager.currentContext?.run {
801-
val currentStack = player.inventory.getStack(hotbarIndex)
802-
val currentSpeed = cachedState.calcItemBlockBreakingDelta(player, world, blockPos, currentStack)
803-
val newSpeed = cachedState.calcItemBlockBreakingDelta(player, world, blockPos, newStack)
804-
newSpeed >= currentSpeed
805-
} != false
806-
}
798+
.filter { BreakManager.currentStackSelection.filterStack(it) }
807799
.let { containerStacks ->
808800
var bestStack = player.mainHandStack
809801
var bestBreakDelta = state.calcItemBlockBreakingDelta(player, world, pos, bestStack)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ data class BreakInfo(
3838

3939
var updatedThisTick = true
4040
var progressedThisTick = false
41+
var serverBreakTicks = 0
4142

4243
var breaking = false
4344
var abandoned = false

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

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ object BreakManager : RequestHandler<BreakRequest>(
110110
it?.breakConfig?.doubleBreak == true || it?.isSecondary == true
111111
}?.context?.itemSelection
112112
?: StackSelection.EVERYTHING.select()
113-
val currentContext
114-
get() = breakInfos.lastOrNull()?.context
115113

116114
private val pendingBreakCount get() = breakInfos.count { it != null } + pendingActions.size
117115
override val blockedPositions
@@ -198,6 +196,12 @@ object BreakManager : RequestHandler<BreakRequest>(
198196
}
199197

200198
listen<RenderEvent.StaticESP> { event ->
199+
val activeStack = breakInfos
200+
.filterNotNull()
201+
.firstOrNull()?.let { info ->
202+
player.inventory.getStack(info.context.hotbarIndex)
203+
} ?: return@listen
204+
201205
breakInfos
202206
.filterNotNull()
203207
.forEach { info ->
@@ -208,7 +212,7 @@ object BreakManager : RequestHandler<BreakRequest>(
208212
world,
209213
info.context.blockPos,
210214
info.breakConfig,
211-
if (!info.isRedundant) player.inventory.getStack(info.context.hotbarIndex) else null
215+
if (!info.isRedundant) activeStack else null
212216
).toDouble()
213217
val currentDelta = info.breakingTicks * breakDelta
214218

@@ -290,7 +294,7 @@ object BreakManager : RequestHandler<BreakRequest>(
290294
}
291295
.also {
292296
it.firstOrNull()?.let { info ->
293-
val minKeepTicks = secondaryBreak?.let { secondary ->
297+
secondaryBreak?.let { secondary ->
294298
val breakDelta = secondary.context.cachedState.calcBreakDelta(
295299
player,
296300
world,
@@ -299,9 +303,17 @@ object BreakManager : RequestHandler<BreakRequest>(
299303
player.inventory.getStack(secondary.context.hotbarIndex)
300304
)
301305
val breakAmount = breakDelta * (secondary.breakingTicks + 1)
302-
if (breakAmount >= 1.0f) 1 else 0
303-
} ?: 0
304-
if (!info.context.requestDependencies(info.request, minKeepTicks)) return@run
306+
val minKeepTicks = if (breakAmount >= 1.0f) 1 else 0
307+
if (!info.context.requestDependencies(info.request, minKeepTicks)) {
308+
secondary.serverBreakTicks = 0
309+
return@run
310+
}
311+
if (minKeepTicks > 0) {
312+
secondary.serverBreakTicks++
313+
}
314+
return@also
315+
}
316+
if (!info.context.requestDependencies(info.request, 0)) return@run
305317
}
306318
}
307319
.asReversed()
@@ -369,19 +381,13 @@ object BreakManager : RequestHandler<BreakRequest>(
369381
// Sanitize the new breaks
370382
val newBreaks = request.contexts
371383
.distinctBy { it.blockPos }
372-
.filter { ctx -> canAccept(ctx) }
373-
.let { acceptable ->
374-
acceptable.firstOrNull()?.let { first ->
375-
acceptable.filter { it.hotbarIndex == first.hotbarIndex }
376-
} ?: acceptable
377-
}
378384
.toMutableList()
379385

380386
// Update the current break infos
381387
breakInfos
382388
.filterNotNull()
383389
.forEach { info ->
384-
newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos }?.let { ctx ->
390+
newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos && canAccept(ctx) }?.let { ctx ->
385391
if (!info.updatedThisTick || info.abandoned) {
386392
info.updateInfo(ctx, request)
387393
if (info.isRedundant)
@@ -418,14 +424,9 @@ object BreakManager : RequestHandler<BreakRequest>(
418424

419425
breakInfos
420426
.lastOrNull { it != null && !it.isRedundant && it.breakConfig.doubleBreak }
421-
?.let { info ->
422-
val currentCtx = info.context
423-
val currentStack = player.inventory.getStack(currentCtx.hotbarIndex)
424-
val currentSpeed = currentCtx.cachedState.calcItemBlockBreakingDelta(player, world, currentCtx.blockPos, currentStack)
427+
?.let { current ->
425428
val newStack = player.inventory.getStack(newCtx.hotbarIndex)
426-
val newSpeed = currentCtx.cachedState.calcItemBlockBreakingDelta(player, world, info.context.blockPos, newStack)
427-
if (!currentCtx.itemSelection.filterStack(newStack) || newSpeed < currentSpeed)
428-
return false
429+
if (!current.context.itemSelection.filterStack(newStack)) return false
429430
}
430431

431432
val blockState = blockState(newCtx.blockPos)
@@ -446,6 +447,8 @@ object BreakManager : RequestHandler<BreakRequest>(
446447

447448
val ctx = iterator.next()
448449

450+
if (!canAccept(ctx)) continue
451+
449452
if (!ctx.requestDependencies(request)) return false
450453
rotationRequest = if (request.config.rotateForBreak) ctx.rotation.submit(false) else null
451454
if (!rotated || tickStage !in request.config.breakStageMask) return false
@@ -469,6 +472,9 @@ object BreakManager : RequestHandler<BreakRequest>(
469472
val iterator = breaks.iterator()
470473
while (iterator.hasNext()) {
471474
val ctx = iterator.next()
475+
476+
if (!canAccept(ctx)) continue
477+
472478
initNewBreak(ctx, request) ?: return false
473479
iterator.remove()
474480
}
@@ -723,7 +729,7 @@ object BreakManager : RequestHandler<BreakRequest>(
723729
}
724730

725731
val swing = config.swing
726-
if (overBreakThreshold) {
732+
if (overBreakThreshold && (!info.isSecondary || info.serverBreakTicks >= info.breakConfig.fudgeFactor + 1)) {
727733
if (info.isPrimary) {
728734
onBlockBreak(info)
729735
info.stopBreakPacket(world, interaction)

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
@@ -56,8 +56,8 @@ object BrokenBlockHandler : PostActionHandler<BreakInfo>() {
5656
val loaded = world.isChunkLoaded(ChunkSectionPos.getSectionCoord(pos.x), ChunkSectionPos.getSectionCoord(pos.z))
5757
if (!loaded) return@let
5858

59-
if (!info.broken) warn("${info::class.simpleName} at ${info.context.blockPos.toShortString()} timed out with cached state ${info.context.cachedState}")
60-
else if (!TaskFlowModule.ignoreItemDropWarnings) warn("${info::class.simpleName}'s item drop at ${info.context.blockPos.toShortString()} timed out")
59+
if (!info.broken) warn("${info.type} ${info::class.simpleName} at ${info.context.blockPos.toShortString()} timed out with cached state ${info.context.cachedState}")
60+
else if (!TaskFlowModule.ignoreItemDropWarnings) warn("${info.type} ${info::class.simpleName}'s item drop at ${info.context.blockPos.toShortString()} timed out")
6161

6262
if (!info.broken && info.breakConfig.breakConfirmation != BreakConfirmationMode.AwaitThenBreak) {
6363
world.setBlockState(info.context.blockPos, info.context.cachedState)

0 commit comments

Comments
 (0)