Skip to content

Commit 30e1beb

Browse files
committed
efficiency check for minKeepTicks
1 parent ab92486 commit 30e1beb

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,27 @@ object BreakManager : RequestHandler<BreakRequest>(
310310
.asReversed()
311311
.also {
312312
it.firstOrNull { it.shouldSwap(player, world) }?.let { info ->
313-
val breakDelta = info.context.cachedState.calcBreakDelta(
313+
val cachedState = info.context.cachedState
314+
val swapStack = player.inventory.getStack(info.context.hotbarIndex)
315+
316+
val breakAmount = cachedState.calcBreakDelta(
317+
player,
318+
world,
319+
info.context.blockPos,
320+
info.breakConfig,
321+
swapStack
322+
) * info.breakingTicks
323+
val breakAmountNoEfficiency = cachedState.calcBreakDelta(
314324
player,
315325
world,
316326
info.context.blockPos,
317327
info.breakConfig,
318-
player.inventory.getStack(info.context.hotbarIndex)
319-
)
320-
val breakAmount = breakDelta * info.breakingTicks
321-
val minKeepTicks = if (breakAmount >= info.getBreakThreshold() &&
328+
swapStack,
329+
ignoreEfficiency = true
330+
) * info.breakingTicks
331+
332+
val minKeepTicks = if ((breakAmount >= info.getBreakThreshold() || info.couldReBreak.value == true) &&
333+
breakAmountNoEfficiency < info.getBreakThreshold() &&
322334
info.serverBreakTicks < info.breakConfig.fudgeFactor)
323335
{
324336
1
@@ -334,8 +346,8 @@ object BreakManager : RequestHandler<BreakRequest>(
334346
}
335347
}
336348
.forEach { info ->
337-
if (!info.shouldProgress) return@forEach
338-
updateBreakProgress(info)
349+
if (info.shouldProgress)
350+
updateBreakProgress(info)
339351
}
340352
}
341353
}
@@ -815,9 +827,10 @@ object BreakManager : RequestHandler<BreakRequest>(
815827
world: BlockView,
816828
pos: BlockPos,
817829
config: BreakConfig,
818-
item: ItemStack? = null
830+
item: ItemStack? = null,
831+
ignoreEfficiency: Boolean = false
819832
) = runSafe {
820-
val delta = calcItemBlockBreakingDelta(player, world, pos, item ?: player.mainHandStack)
833+
val delta = calcItemBlockBreakingDelta(player, world, pos, item ?: player.mainHandStack, ignoreEfficiency)
821834
//ToDo: This setting requires some fixes / improvements in the player movement prediction to work properly. Currently, it's broken
822835
// if (config.desyncFix) {
823836
// val nextTickPrediction = buildPlayerPrediction().next()

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,23 @@ object BlockUtils {
247247
player: PlayerEntity,
248248
world: BlockView,
249249
blockPos: BlockPos,
250-
item: ItemStack
250+
item: ItemStack,
251+
ignoreEfficiency: Boolean = false
251252
): Float {
252253
val hardness = getHardness(world, blockPos)
253254
return if (hardness == -1.0f) 0.0f else {
254255
val harvestMultiplier = if (item.canHarvest(this)) 30 else 100
255-
player.getItemBlockBreakingSpeed(this, item) / hardness / harvestMultiplier
256+
player.getItemBlockBreakingSpeed(this, item, ignoreEfficiency) / hardness / harvestMultiplier
256257
}
257258
}
258259

259260
fun ItemStack.canHarvest(blockState: BlockState) =
260261
!blockState.isToolRequired || isSuitableFor(blockState)
261262

262-
fun PlayerEntity.getItemBlockBreakingSpeed(blockState: BlockState, item: ItemStack): Float {
263+
fun PlayerEntity.getItemBlockBreakingSpeed(blockState: BlockState, item: ItemStack, ignoreEfficiency: Boolean = false): Float {
263264
var speedMultiplier = item.getMiningSpeedMultiplier(blockState)
264265
if (speedMultiplier > 1.0f) {
265-
val level = item.getEnchantment(Enchantments.EFFICIENCY)
266+
val level = if (ignoreEfficiency) 0 else item.getEnchantment(Enchantments.EFFICIENCY)
266267
if (level > 0 && !item.isEmpty) {
267268
speedMultiplier += (level * level + 1)
268269
}

0 commit comments

Comments
 (0)