Skip to content

Commit 1b3aced

Browse files
committed
misc small bug fixes and confirm break timeout
1 parent adf42c0 commit 1b3aced

File tree

4 files changed

+42
-27
lines changed

4 files changed

+42
-27
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface BuildConfig {
2929
val breakThreshold: Float
3030
val rotateForBreak: Boolean
3131
val breakConfirmation: Boolean
32+
val breakTimeout: Int
3233
val maxPendingBreaks: Int
3334
val breaksPerTick: Int
3435
val breakWeakBlocks: Boolean

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class BuildSettings(
4040
override val breakThreshold by c.setting("Break Threshold", 1.0f, 0.1f..1.0f, 0.1f, "The amount broken, between 0.0 and 1.0, a block should be considered broken") { vis() && page == Page.BREAK }
4141
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking") { vis() && page == Page.BREAK }
4242
override val breakConfirmation by c.setting("Break Confirmation", false, "Wait for block break confirmation") { vis() && page == Page.BREAK }
43+
override val breakTimeout by c.setting("Break Timeout", 10, 1..30, 1, "Timeout for breaking in ticks", unit = "ticks") { vis() && page == Page.BREAK }
4344
override val maxPendingBreaks by c.setting("Max Pending Breaks", 1, 1..10, 1, "Maximum pending block breaks") { vis() && page == Page.BREAK }
4445
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.BREAK }
4546
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.BREAK }

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ object PacketMineTaskRewrite : Module(
7171
) { page == Page.General }
7272
private val interactionDelay by setting(
7373
"Interact Delay",
74-
0,
75-
0..5,
76-
1,
74+
false,
7775
"The delay between interacting with blocks",
78-
"ticks"
7976
) { page == Page.General }
8077
private val swingHand by setting(
8178
"Swing Hand",

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

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ class PacketBreakBlock @Ta5kBuilder constructor(
6161
private val breakingTexture: Boolean = true,
6262
private val sounds: Boolean = true,
6363
private val particles: Boolean = true,
64+
private val obeyInteractionDelays: Boolean = false,
6465
private val collectDrop: Boolean = false,
66+
private val rotate: Boolean = TaskFlowModule.build.rotateForBreak,
6567
private val rotation: RotationConfig = TaskFlowModule.rotation,
6668
private val interact: InteractionConfig = TaskFlowModule.interact,
6769
private val sides: Set<Direction> = Direction.entries.toSet(),
68-
private val rotate: Boolean = TaskFlowModule.build.rotateForBreak,
6970
) : Task<ItemEntity?>() {
7071
override val name get() = "Packet breaking ${ctx.result.blockPos.toShortString()}"
7172

@@ -93,6 +94,7 @@ class PacketBreakBlock @Ta5kBuilder constructor(
9394
private var soundCooldown = 0.0f
9495

9596
private var pendingConfirmation = false
97+
private var pendingConfirmationStartTimestamp = 0L
9698

9799
enum class State {
98100
BREAKING, COLLECTING
@@ -128,33 +130,43 @@ class PacketBreakBlock @Ta5kBuilder constructor(
128130
}
129131

130132
listen<TickEvent.Pre> {
131-
side = mc.crosshairTarget?.blockResult?.side ?: ctxSide
133+
mc.crosshairTarget?.blockResult?.side?.let { currentBlockHitSide ->
134+
side = currentBlockHitSide
135+
}
132136

133-
drop?.let { itemDrop ->
134-
if (!collectDrop) {
135-
breakBlock()
136-
success(itemDrop)
137-
return@listen
138-
}
137+
if (pendingConfirmation) {
138+
drop?.let { itemDrop ->
139+
if (!collectDrop) {
140+
breakBlock()
141+
success(itemDrop)
142+
return@listen
143+
}
139144

140-
if (!world.entities.contains(itemDrop)) {
141-
BaritoneUtils.cancel()
142-
success(itemDrop)
143-
return@listen
144-
}
145+
if (!world.entities.contains(itemDrop)) {
146+
BaritoneUtils.cancel()
147+
success(itemDrop)
148+
return@listen
149+
}
145150

146-
if (player.hotbarAndStorage.none { it.isEmpty }) {
147-
player.currentScreenHandler.inventorySlots.firstOrNull {
148-
it.stack.item.block in TaskFlowModule.inventory.disposables
149-
}?.let {
150-
clickSlot(it.id, 1, SlotActionType.THROW)
151+
if (player.hotbarAndStorage.none { it.isEmpty }) {
152+
player.currentScreenHandler.inventorySlots.firstOrNull {
153+
it.stack.item.block in TaskFlowModule.inventory.disposables
154+
}?.let {
155+
clickSlot(it.id, 1, SlotActionType.THROW)
156+
}
157+
return@listen
151158
}
159+
160+
BaritoneUtils.setGoalAndPath(GoalBlock(itemDrop.blockPos))
152161
return@listen
162+
} ?: run {
163+
BaritoneUtils.cancel()
164+
if (getPendingTime() >= TaskFlowModule.build.breakTimeout
165+
) {
166+
failure("Packet break timed out.")
167+
}
153168
}
154-
155-
BaritoneUtils.setGoalAndPath(GoalBlock(itemDrop.blockPos))
156-
return@listen
157-
} ?: BaritoneUtils.cancel()
169+
}
158170

159171
if (pendingConfirmation) return@listen
160172

@@ -166,7 +178,7 @@ class PacketBreakBlock @Ta5kBuilder constructor(
166178
player, world, blockPos, toolStack!!
167179
)
168180
val previousBreakDelta = currentBlockState.calcItemBlockBreakingDelta(
169-
player, world, blockPos, toolStack!!
181+
player, world, blockPos, previousToolStack!!
170182
)
171183
val multiplier = currentBreakDelta / previousBreakDelta
172184
progress *= multiplier
@@ -337,6 +349,7 @@ class PacketBreakBlock @Ta5kBuilder constructor(
337349
private fun SafeContext.onBlockBreak() {
338350
if (internalBreakConfirmation) {
339351
pendingConfirmation = true
352+
pendingConfirmationStartTimestamp = System.currentTimeMillis()
340353
} else {
341354
breakBlock()
342355
success(null)
@@ -367,6 +380,9 @@ class PacketBreakBlock @Ta5kBuilder constructor(
367380
)
368381
}
369382

383+
private fun getPendingTime() =
384+
System.currentTimeMillis() - pendingConfirmationStartTimestamp
385+
370386
private fun SafeContext.swing() =
371387
player.swingHand(player.activeHand)
372388

0 commit comments

Comments
 (0)