Skip to content

Commit df30395

Browse files
committed
remove efficiency ignore checks as they're causing issues. From testing, this fixes the last inconsistency issue with actual breaking
1 parent 97ff0d2 commit df30395

File tree

4 files changed

+44
-48
lines changed

4 files changed

+44
-48
lines changed

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import com.lambda.interaction.request.breaking.BrokenBlockHandler.pendingActions
6666
import com.lambda.interaction.request.breaking.BrokenBlockHandler.setPendingConfigs
6767
import com.lambda.interaction.request.breaking.BrokenBlockHandler.startPending
6868
import com.lambda.interaction.request.breaking.SwapInfo.Companion.getSwapInfo
69+
import com.lambda.interaction.request.hotbar.HotbarRequest
6970
import com.lambda.interaction.request.interacting.InteractionManager
7071
import com.lambda.interaction.request.placing.PlaceManager
7172
import com.lambda.interaction.request.rotating.RotationRequest
@@ -428,8 +429,16 @@ object BreakManager : RequestHandler<BreakRequest>(
428429
infos.firstOrNull()?.let { info ->
429430
infos.lastOrNull { it.swapInfo.swap && it.shouldProgress }?.let { last ->
430431
val minSwapTicks = max(info.swapInfo.minKeepTicks, last.swapInfo.minKeepTicks)
431-
if (!info.context.requestSwap(info.request, minSwapTicks))
432+
val hotbarRequest = with(info) {
433+
HotbarRequest(
434+
context.hotbarIndex,
435+
request.hotbar,
436+
request.hotbar.keepTicks.coerceAtLeast(minSwapTicks)
437+
).submit(false)
438+
}
439+
if (!hotbarRequest.done) {
432440
return false
441+
}
433442
if (minSwapTicks > 0) {
434443
val alreadySwapped = swappedThisTick
435444
currentStack = info.swapStack
@@ -513,8 +522,8 @@ object BreakManager : RequestHandler<BreakRequest>(
513522
return secondaryBreak
514523
}
515524

516-
primaryInfo.stopBreakPacket(world, interaction)
517-
primaryInfo.makeSecondary()
525+
secondaryBreak = primaryInfo.apply { type = Secondary }
526+
secondaryBreak?.stopBreakPacket(world, interaction)
518527
return@let
519528
}
520529

@@ -615,17 +624,6 @@ object BreakManager : RequestHandler<BreakRequest>(
615624
swapInfo = getSwapInfo(this, player, world)
616625
}
617626

618-
/**
619-
* Makes the [BreakInfo] a secondary if not already.
620-
*/
621-
private fun BreakInfo.makeSecondary() {
622-
if (secondaryBreak === this) return
623-
secondaryBreak = this.apply {
624-
type = Secondary
625-
}
626-
primaryBreak = null
627-
}
628-
629627
/**
630628
* Attempts to cancel the break.
631629
*
@@ -715,12 +713,8 @@ object BreakManager : RequestHandler<BreakRequest>(
715713
}
716714

717715
info.breakingTicks++
718-
val progress = blockState.calcBreakDelta(
719-
player,
720-
world,
721-
ctx.blockPos,
722-
config
723-
) * (info.breakingTicks - config.fudgeFactor)
716+
val breakDelta = blockState.calcBreakDelta(player, world, ctx.blockPos, config)
717+
val progress = breakDelta * (info.breakingTicks - config.fudgeFactor)
724718

725719
if (config.sounds) {
726720
if (info.soundsCooldown % 4.0f == 0.0f) {
@@ -748,7 +742,7 @@ object BreakManager : RequestHandler<BreakRequest>(
748742
}
749743

750744
val swing = config.swing
751-
if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) {
745+
if (progress >= info.getBreakThreshold() && info.swapInfo.validSwap) {
752746
if (info.type == Primary) {
753747
onBlockBreak(info)
754748
info.stopBreakPacket(world, interaction)
@@ -821,8 +815,11 @@ object BreakManager : RequestHandler<BreakRequest>(
821815
}
822816

823817
val progress = blockState.calcBreakDelta(player, world, ctx.blockPos, info.breakConfig)
824-
info.vanillaInstantBreakable = progress >= 1 && info.swapInfo.canCompleteBreak
825-
if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) {
818+
819+
val instantBreakable = progress >= info.getBreakThreshold() && info.swapInfo.validSwap
820+
info.vanillaInstantBreakable = progress >= 1 && info.swapInfo.validSwap
821+
822+
if (instantBreakable) {
826823
onBlockBreak(info)
827824
if (!info.vanillaInstantBreakable) breakCooldown = info.breakConfig.breakDelay
828825
} else {
@@ -842,7 +839,7 @@ object BreakManager : RequestHandler<BreakRequest>(
842839

843840
info.startBreakPacket(world, interaction)
844841

845-
if (info.type == Secondary || (!info.vanillaInstantBreakable && progress >= info.breakConfig.breakThreshold)) {
842+
if (info.type == Secondary || (instantBreakable && !info.vanillaInstantBreakable)) {
846843
info.stopBreakPacket(world, interaction)
847844
}
848845

@@ -854,10 +851,9 @@ object BreakManager : RequestHandler<BreakRequest>(
854851
world: BlockView,
855852
pos: BlockPos,
856853
config: BreakConfig,
857-
item: ItemStack? = null,
858-
ignoreEfficiency: Boolean = false
854+
item: ItemStack? = null
859855
) = runSafe {
860-
val delta = calcItemBlockBreakingDelta(player, world, pos, item ?: player.mainHandStack, ignoreEfficiency)
856+
val delta = calcItemBlockBreakingDelta(player, world, pos, item ?: player.mainHandStack)
861857
//ToDo: This setting requires some fixes / improvements in the player movement prediction to work properly. Currently, it's broken
862858
// if (config.desyncFix) {
863859
// val nextTickPrediction = buildPlayerPrediction().next()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object RebreakHandler {
8989
val context = reBreak.context
9090
val breakDelta = context.cachedState.calcBreakDelta(player, world, context.blockPos, reBreak.breakConfig)
9191
val breakTicks = reBreak.breakingTicks - reBreak.breakConfig.fudgeFactor
92-
return@runSafe if (breakTicks * breakDelta >= reBreak.getBreakThreshold() && reBreak.swapInfo.canCompleteBreak) {
92+
return@runSafe if (breakTicks * breakDelta >= reBreak.getBreakThreshold() && reBreak.swapInfo.validSwap) {
9393
if (reBreak.breakConfig.breakConfirmation != BreakConfig.BreakConfirmationMode.AwaitThenBreak) {
9494
destroyBlock(reBreak)
9595
}

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.interaction.request.breaking
1919

20+
import com.lambda.Lambda.mc
2021
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary
2122
import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak
2223
import com.lambda.interaction.request.breaking.BreakManager.calcBreakDelta
@@ -27,14 +28,18 @@ import net.minecraft.item.ItemStack
2728
import net.minecraft.world.BlockView
2829

2930
data class SwapInfo(
30-
val type: BreakInfo.BreakType,
31-
val breakConfig: BreakConfig = TaskFlowModule.build.breaking,
31+
private val type: BreakInfo.BreakType,
32+
private val breakConfig: BreakConfig = TaskFlowModule.build.breaking,
3233
val swap: Boolean = false,
3334
val minKeepTicks: Int = 0,
3435
) {
35-
val canCompleteBreak
36-
get() = BreakManager.heldTicks >= if (type == Primary || type == Rebreak) breakConfig.serverSwapTicks
37-
else breakConfig.serverSwapTicks.coerceAtLeast(3)
36+
val validSwap
37+
get() = run {
38+
val serverSwapTicks = if (type == Primary || type == Rebreak) breakConfig.serverSwapTicks
39+
else breakConfig.serverSwapTicks.coerceAtLeast(3)
40+
41+
(mc.player?.mainHandStack?.heldTicks ?: return false) >= serverSwapTicks
42+
}
3843

3944
companion object {
4045
val EMPTY = SwapInfo(Primary)
@@ -46,8 +51,6 @@ data class SwapInfo(
4651
): SwapInfo = with(info) {
4752
val breakDelta = context.cachedState
4853
.calcBreakDelta(player, world, context.blockPos, breakConfig, swapStack)
49-
val breakDeltaNoEfficiency = context.cachedState
50-
.calcBreakDelta(player, world, context.blockPos, breakConfig, swapStack, ignoreEfficiency = true)
5154

5255
val threshold = getBreakThreshold()
5356

@@ -56,16 +59,14 @@ data class SwapInfo(
5659
else breakingTicks).let {
5760
// Plus one as this is calculated before this ticks progress is calculated and the breakingTicks are incremented
5861
(it + 1).let {
59-
if (breakDelta >= threshold) it else it - breakConfig.fudgeFactor
62+
if (breakDelta >= threshold || !info.breaking) it else (it - breakConfig.fudgeFactor)
6063
}
6164
}
6265

6366
val minKeepTicks = run {
6467
if (type == Primary) {
6568
val swapTickProgress = breakDelta * (breakTicks + breakConfig.serverSwapTicks - 1)
66-
val withoutEfficiency = breakDeltaNoEfficiency * breakTicks >= threshold
67-
if (swapTickProgress >= threshold &&
68-
!withoutEfficiency) 1
69+
if (swapTickProgress >= threshold) 1
6970
else 0
7071
} else {
7172
val serverSwapTicks = breakConfig.serverSwapTicks.coerceAtLeast(3)
@@ -91,7 +92,7 @@ data class SwapInfo(
9192
}
9293

9394
private val ItemStack.heldTicks
94-
get() = if (currentStack == this)
95+
get() = if (this == currentStack)
9596
BreakManager.heldTicks
9697
else 0
9798
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,12 @@ object BlockUtils {
256256
player: PlayerEntity,
257257
world: BlockView,
258258
blockPos: BlockPos,
259-
item: ItemStack,
260-
ignoreEfficiency: Boolean = false
259+
item: ItemStack
261260
): Float {
262261
val hardness = getHardness(world, blockPos)
263262
return if (hardness == -1.0f) 0.0f else {
264263
val harvestMultiplier = if (item.canHarvest(this)) 30 else 100
265-
player.getItemBlockBreakingSpeed(this, item, ignoreEfficiency) / hardness / harvestMultiplier
264+
player.getItemBlockBreakingSpeed(this, item) / hardness / harvestMultiplier
266265
}
267266
}
268267

@@ -271,14 +270,13 @@ object BlockUtils {
271270

272271
fun PlayerEntity.getItemBlockBreakingSpeed(
273272
blockState: BlockState,
274-
item: ItemStack,
275-
ignoreEfficiency: Boolean = false
273+
item: ItemStack
276274
): Float {
277275
var speedMultiplier = item.getMiningSpeedMultiplier(blockState)
278276
if (speedMultiplier > 1.0f) {
279-
val level = if (ignoreEfficiency) 0 else item.getEnchantment(Enchantments.EFFICIENCY)
280-
if (level > 0 && !item.isEmpty) {
281-
speedMultiplier += (level * level + 1)
277+
speedMultiplier += item.getEnchantment(Enchantments.EFFICIENCY).let {
278+
if (it > 0) (it * it) + 1
279+
else 0
282280
}
283281
}
284282

@@ -298,6 +296,7 @@ object BlockUtils {
298296
speedMultiplier *= fatigueMultiplier
299297
}
300298

299+
speedMultiplier *= getAttributeValue(EntityAttributes.BLOCK_BREAK_SPEED).toFloat()
301300
if (isSubmergedIn(FluidTags.WATER)) {
302301
getAttributeInstance(EntityAttributes.SUBMERGED_MINING_SPEED)?.let { speed ->
303302
speedMultiplier *= speed.getValue().toFloat()

0 commit comments

Comments
 (0)