Skip to content

Commit f8c40e0

Browse files
committed
fixed instamine with silent swap
1 parent 4c6c912 commit f8c40e0

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ data class BreakContext(
4141
override val checkedState: BlockState,
4242
override val targetState: TargetState,
4343
override var hotbarIndex: Int,
44-
val instantBreak: Boolean,
44+
var instantBreak: Boolean,
4545
) : BuildContext {
4646
private val baseColor = Color(222, 0, 0, 25)
4747
private val sideColor = Color(222, 0, 0, 100)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ object BuildSimulator {
410410
state,
411411
targetState,
412412
player.inventory.selectedSlot,
413-
instantBreakable(state, pos)
413+
instantBreakable(state, pos, build.breakSettings.breakThreshold)
414414
)
415415
acc.add(BreakResult.Break(pos, breakContext))
416416
return acc
@@ -455,7 +455,7 @@ object BuildSimulator {
455455
val blockHit = bestHit.hit.blockResult ?: return acc
456456
val target = lookAt(bestHit.targetRotation, 0.001)
457457
val request = RotationRequest(target, rotation)
458-
val instant = instantBreakable(state, pos)
458+
val instant = instantBreakable(state, pos, build.breakSettings.breakThreshold)
459459

460460
val breakContext = BreakContext(
461461
eye, blockHit, request, state, targetState, player.inventory.selectedSlot, instant
@@ -513,7 +513,8 @@ object BuildSimulator {
513513
if (toolPair == null) return acc
514514

515515
breakContext.hotbarIndex = player.hotbar.indexOf(toolPair.first)
516+
breakContext.instantBreak = instantBreakable(state, pos, toolPair.first, build.breakSettings.breakThreshold)
516517
acc.add(BreakResult.Break(pos, breakContext))
517518
return acc
518519
}
519-
}
520+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ class BuildTask @Ta5kBuilder constructor(
166166
.sorted()
167167
.take(build.breakSettings.breaksPerTick)
168168

169-
if (instantResults.isNotEmpty()) {
169+
instantResults.firstOrNull()?.let { firstInstant ->
170+
if (!hotbar.request(HotbarRequest(firstInstant.context.hotbarIndex)).done) return@onRotate
170171
build.breakSettings.request(BreakRequest(instantResults.map { it.context }, build, rotation) { breaks++ })
171172
return@onRotate
172173
}

common/src/main/kotlin/com/lambda/util/BlockUtils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ object BlockUtils {
235235
fun SafeContext.fluidState(pos: BlockPos): FluidState = world.getFluidState(pos)
236236
fun SafeContext.blockEntity(pos: BlockPos) = world.getBlockEntity(pos)
237237

238-
fun SafeContext.instantBreakable(blockState: BlockState, blockPos: BlockPos): Boolean {
239-
val ticksNeeded = 1 / blockState.calcBlockBreakingDelta(player, world, blockPos)
238+
fun SafeContext.instantBreakable(blockState: BlockState, blockPos: BlockPos, breakThreshold: Float): Boolean {
239+
val ticksNeeded = 1 / (blockState.calcBlockBreakingDelta(player, world, blockPos) / breakThreshold)
240240
return (ticksNeeded <= 1 && ticksNeeded != 0f) || player.isCreative
241241
}
242242

243-
fun SafeContext.instantBreakable(blockState: BlockState, blockPos: BlockPos, item: ItemStack): Boolean {
244-
val ticksNeeded = 1 / blockState.calcItemBlockBreakingDelta(player, world, blockPos, item)
243+
fun SafeContext.instantBreakable(blockState: BlockState, blockPos: BlockPos, item: ItemStack, breakThreshold: Float): Boolean {
244+
val ticksNeeded = 1 / (blockState.calcItemBlockBreakingDelta(player, world, blockPos, item) / breakThreshold)
245245
return (ticksNeeded <= 1 && ticksNeeded != 0f) || player.isCreative
246246
}
247247

0 commit comments

Comments
 (0)