Skip to content

Commit 1288503

Browse files
committed
repeat the accept and start break cycle in case blocks are broken and new contexts can be accepted
1 parent d58efae commit 1288503

File tree

8 files changed

+58
-70
lines changed

8 files changed

+58
-70
lines changed

common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import net.minecraft.entity.Entity;
2626
import net.minecraft.entity.player.PlayerEntity;
2727
import net.minecraft.entity.player.PlayerInventory;
28-
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
2928
import net.minecraft.screen.slot.SlotActionType;
3029
import net.minecraft.util.ActionResult;
3130
import net.minecraft.util.Hand;

common/src/main/kotlin/com/lambda/config/groups/BreakSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class BreakSettings(
3434
override val breakThreshold by c.setting("Break Threshold", 0.7f, 0.1f..1.0f, 0.02f, "The break amount at which the block is considered broken") { vis() }
3535
override val doubleBreak by c.setting("Double Break", true, "Allows breaking two blocks at once") { vis() }
3636
override val breakDelay by c.setting("Break Delay", 0, 0..6, 1, "The delay between breaking blocks", " ticks") { vis() }
37-
override val breakStageMask by c.setting("Break Stage Mask", setOf(TickEvent.Pre, TickEvent.Input.Pre, TickEvent.Player.Post), "The sub-tick timing at which break actions can be performed", vis)
37+
override val breakStageMask by c.setting("Break Stage Mask", setOf(TickEvent.Pre, TickEvent.Input.Pre, TickEvent.Input.Post, TickEvent.Player.Post), "The sub-tick timing at which break actions can be performed", vis)
3838
override val swing by c.setting("Swing Mode", SwingMode.Constant, "The times at which to swing the players hand") { vis() }
3939
override val swingType by c.setting("Break Swing Type", BuildConfig.SwingType.Vanilla, "The style of swing") { vis() && swing != SwingMode.None }
4040
override val sounds by c.setting("Break Sounds", true, "Plays the breaking sounds") { vis() }

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

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ import com.lambda.util.player.swingHand
5555
import net.minecraft.client.sound.PositionedSoundInstance
5656
import net.minecraft.client.sound.SoundInstance
5757
import net.minecraft.entity.ItemEntity
58-
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
59-
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action
6058
import net.minecraft.sound.SoundCategory
6159
import net.minecraft.util.Hand
6260
import net.minecraft.util.math.BlockPos
@@ -65,6 +63,7 @@ object BreakManager : RequestHandler<BreakRequest>(
6563
0,
6664
TickEvent.Pre,
6765
TickEvent.Input.Pre,
66+
TickEvent.Input.Post,
6867
TickEvent.Player.Post,
6968
// ToDo: Post interact
7069
onOpen = { processRequest(activeRequest) }
@@ -203,36 +202,38 @@ object BreakManager : RequestHandler<BreakRequest>(
203202
private fun SafeContext.processRequest(breakRequest: BreakRequest?) {
204203
pendingBreaks.cleanUp()
205204

206-
breakRequest?.let { request ->
207-
if (request.fresh) populateFrom(request)
205+
repeat(2) {
206+
breakRequest?.let { request ->
207+
if (request.fresh) populateFrom(request)
208208

209-
if (performInstantBreaks(request)) {
210-
processNewBreaks(request)
209+
if (performInstantBreaks(request)) {
210+
processNewBreaks(request)
211+
}
211212
}
212-
}
213213

214-
// Reversed so that the breaking order feels natural to the user as the primary break is always the
215-
// last break to be started
216-
run {
217-
breakInfos
218-
.filterNotNull()
219-
.filter { !it.isRedundant && it.updatedThisTick }
220-
.also {
221-
rotationRequest = it.firstOrNull { info -> info.breakConfig.rotateForBreak }
222-
?.let { info ->
223-
val rotation = info.context.rotation
224-
if (instantBreaks.isEmpty()) info.request.rotation.request(rotation, false) else rotation
225-
}
226-
}
227-
.asReversed()
228-
.forEach { info ->
229-
if (info.updatedProgressThisTick) return@forEach
230-
if (!info.context.requestDependencies(info.request)) return@run
231-
if (tickStage !in info.breakConfig.breakStageMask) return@forEach
232-
if ((!rotated && info.isPrimary)) return@run
233-
234-
updateBreakProgress(info)
235-
}
214+
// Reversed so that the breaking order feels natural to the user as the primary break is always the
215+
// last break to be started
216+
run {
217+
breakInfos
218+
.filterNotNull()
219+
.filter { !it.isRedundant && it.updatedThisTick }
220+
.also {
221+
rotationRequest = it.firstOrNull { info -> info.breakConfig.rotateForBreak }
222+
?.let { info ->
223+
val rotation = info.context.rotation
224+
if (instantBreaks.isEmpty()) info.request.rotation.request(rotation, false) else rotation
225+
}
226+
}
227+
.asReversed()
228+
.forEach { info ->
229+
if (info.updatedProgressThisTick) return@forEach
230+
if (!info.context.requestDependencies(info.request)) return@run
231+
if (tickStage !in info.breakConfig.breakStageMask) return@forEach
232+
if ((!rotated && info.isPrimary)) return@run
233+
234+
updateBreakProgress(info)
235+
}
236+
}
236237
}
237238

238239
if (instantBreaks.isEmpty() && breaks.isEmpty()) {
@@ -330,15 +331,13 @@ object BreakManager : RequestHandler<BreakRequest>(
330331
* @return false if a context cannot be started or the maximum active breaks has been reached.
331332
*
332333
* @see initNewBreak
333-
* @see atMaxBreakInfos
334334
*/
335335
private fun SafeContext.processNewBreaks(request: BreakRequest): Boolean {
336336
val iterator = breaks.iterator()
337337
while (iterator.hasNext()) {
338338
val ctx = iterator.next()
339339
initNewBreak(ctx, request) ?: return false
340340
iterator.remove()
341-
if (atMaxBreakInfos(request.build.breaking)) return false
342341
}
343342
return true
344343
}
@@ -376,14 +375,6 @@ object BreakManager : RequestHandler<BreakRequest>(
376375
return primaryBreak
377376
}
378377

379-
/**
380-
* @return if the [breakInfos] are at capacity and no new breaks can be started.
381-
*/
382-
private fun atMaxBreakInfos(breakConfig: BreakConfig): Boolean {
383-
val possibleBreakingCount = if (breakConfig.doubleBreak) 2 else 1
384-
return breakInfos.take(possibleBreakingCount).all { it != null }
385-
}
386-
387378
/**
388379
* Begins the post-break logic sequence for the given [info].
389380
*
@@ -504,9 +495,7 @@ object BreakManager : RequestHandler<BreakRequest>(
504495
breakCooldown = info.breakConfig.breakDelay
505496
lastPosStarted = ctx.expectedPos
506497
onBlockBreak(info)
507-
interaction.sendSequencedPacket(world) { sequence ->
508-
PlayerActionC2SPacket(Action.START_DESTROY_BLOCK, ctx.expectedPos, hitResult.side, sequence)
509-
}
498+
info.startBreakPacket(world, interaction)
510499
val swing = info.breakConfig.swing
511500
if (swing.isEnabled()) {
512501
swingHand(info.breakConfig.swingType, Hand.MAIN_HAND)
@@ -601,9 +590,7 @@ object BreakManager : RequestHandler<BreakRequest>(
601590
if (overBreakThreshold) {
602591
if (info.isPrimary) {
603592
onBlockBreak(info)
604-
interaction.sendSequencedPacket(world) { sequence ->
605-
PlayerActionC2SPacket(Action.STOP_DESTROY_BLOCK, ctx.expectedPos, hitResult.side, sequence)
606-
}
593+
info.stopBreakPacket(world, interaction)
607594
} else {
608595
onBlockBreak(info)
609596
}
@@ -633,9 +620,7 @@ object BreakManager : RequestHandler<BreakRequest>(
633620
lastPosStarted = ctx.expectedPos
634621
onBlockBreak(info)
635622
info.request.onStart?.invoke(ctx.expectedPos)
636-
interaction.sendSequencedPacket(world) { sequence: Int ->
637-
PlayerActionC2SPacket(Action.START_DESTROY_BLOCK, ctx.expectedPos, ctx.result.side, sequence)
638-
}
623+
info.startBreakPacket(world, interaction)
639624
breakCooldown = info.breakConfig.breakDelay
640625
return true
641626
}

common/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
4040
1,
4141
TickEvent.Pre,
4242
TickEvent.Input.Pre,
43+
TickEvent.Input.Post,
4344
TickEvent.Player.Post,
4445
// ToDo: Post interact
4546
onClose = { checkResetSwap() }

common/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
6161
0,
6262
TickEvent.Pre,
6363
TickEvent.Input.Pre,
64+
TickEvent.Input.Post,
6465
TickEvent.Player.Post,
6566
// ToDo: Post interact
6667
onOpen = { activeRequest?.let { processRequest(it) } }

common/src/main/kotlin/com/lambda/interaction/request/rotation/RotationManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ object RotationManager : RequestHandler<RotationRequest>(
5151
1,
5252
TickEvent.Pre,
5353
TickEvent.Input.Pre,
54+
TickEvent.Input.Post,
5455
TickEvent.Player.Post,
5556
// ToDo: Post interact
5657
) {

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import com.lambda.interaction.construction.blueprint.TickingBlueprint.Companion.
2121
import com.lambda.interaction.construction.verify.TargetState
2222
import com.lambda.module.Module
2323
import com.lambda.module.tag.ModuleTag
24-
import com.lambda.task.Task
2524
import com.lambda.task.RootTask.run
25+
import com.lambda.task.Task
2626
import com.lambda.task.tasks.BuildTask.Companion.build
2727
import com.lambda.util.BlockUtils.blockPos
2828
import com.lambda.util.BlockUtils.blockState
@@ -44,26 +44,26 @@ object Nuker : Module(
4444
init {
4545
onEnable {
4646
task = tickingBlueprint {
47-
val selection = BlockPos.iterateOutwards(player.blockPos, width, height, width)
48-
.asSequence()
47+
val selection = BlockPos.iterateOutwards(player.blockPos, width, height, width)
48+
.asSequence()
49+
.map { it.blockPos }
50+
.filter { !world.isAir(it) }
51+
.filter { !flatten || it.y >= player.blockPos.y }
52+
.filter { !onlyBreakInstant || blockState(it).getHardness(world, it) <= 1 }
53+
.filter { blockState(it).getHardness(world, it) >= 0 }
54+
.associateWith { TargetState.Air }
55+
56+
if (fillFloor) {
57+
val floor = BlockPos.iterateOutwards(player.blockPos.down(), width, 0, width)
4958
.map { it.blockPos }
50-
.filter { !world.isAir(it) }
51-
.filter { !flatten || it.y >= player.blockPos.y }
52-
.filter { !onlyBreakInstant || blockState(it).getHardness(world, it) <= 1 }
53-
.filter { blockState(it).getHardness(world, it) >= 0 }
54-
.associateWith { TargetState.Air }
59+
.associateWith { TargetState.Solid }
60+
return@tickingBlueprint selection + floor
61+
}
5562

56-
if (fillFloor) {
57-
val floor = BlockPos.iterateOutwards(player.blockPos.down(), width, 0, width)
58-
.map { it.blockPos }
59-
.associateWith { TargetState.Solid }
60-
return@tickingBlueprint selection + floor
61-
}
63+
selection
64+
}.build()
65+
// ToDo: Add build setting delegates
6266

63-
selection
64-
}
65-
// ToDo: Add build setting delegates
66-
.build()
6767
task?.run()
6868
}
6969

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ object PacketMine : Module(
105105
}
106106
}
107107
positions.removeIf { breakPos ->
108-
breakPositions.any { it == breakPos } || queuePositions.any { it == pos }
108+
breakPositions.any { it == breakPos }
109+
|| (queue && queuePositions.any { it == pos })
109110
}
110111
if (positions.isEmpty()) return@listen
111112
val activeBreaking = if (queue) {
@@ -150,7 +151,7 @@ object PacketMine : Module(
150151
onReBreak = { reBreakPos = it },
151152
onItemDrop = { _ -> itemDrops++ }
152153
)
153-
breakConfig.request(request)
154+
breakConfig.request(request, true)
154155
}
155156

156157
private fun SafeContext.breakContexts(positions: Collection<BlockPos?>) =

0 commit comments

Comments
 (0)