Skip to content

Commit bed22da

Browse files
committed
use calcItemBlockBreakingProgress when checking min keep ticks and slight hotbar manager rework
1 parent 43f85c4 commit bed22da

File tree

8 files changed

+40
-33
lines changed

8 files changed

+40
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BreakSettings(
3333
override val unsafeCancels by c.setting("Unsafe Cancels", true, "Allows cancelling block breaking even if the server might continue breaking sever side, potentially causing unexpected state changes") { vis() }
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() }
36-
override val doubleBreakFudgeFactor by c.setting("Double Break Fudge Factor", 1, 0..3, 1, "The amount of ticks to give double, aka secondary breaks extra for the server to recognise the break") { doubleBreak && vis() }
36+
override val doubleBreakFudgeFactor by c.setting("Double Break Fudge Factor", 3, 0..3, 1, "The amount of ticks to give double, aka secondary breaks extra for the server to recognise the break") { doubleBreak && vis() }
3737
override val breakDelay by c.setting("Break Delay", 0, 0..6, 1, "The delay between breaking blocks", " ticks") { vis() }
3838
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)
3939
override val swing by c.setting("Swing Mode", SwingMode.Constant, "The times at which to swing the players hand") { vis() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ class HotbarSettings(
3131
override val swapDelay by c.setting("Swap Delay", 0, 0..3, 1, "The number of ticks delay before allowing another hotbar selection swap", " ticks", vis)
3232
override val swapsPerTick by c.setting("Swaps Per Tick", 3, 1..10, 1, "The number of hotbar selection swaps that can take place each tick") { swapDelay <= 0 && vis() }
3333
override val swapPause by c.setting("Swap Pause", 0, 0..20, 1, "The delay in ticks to pause actions after switching to the slot", " ticks", vis)
34-
override val sequenceStageMask by c.setting("Hotbar Stage Mask", setOf(TickEvent.Pre, TickEvent.Input.Pre, TickEvent.Player.Post), "The sub-tick timing at which hotbar actions are performed", vis)
34+
override val sequenceStageMask by c.setting("Hotbar Stage Mask", setOf(TickEvent.Input.Pre, TickEvent.Input.Post), "The sub-tick timing at which hotbar actions are performed", vis)
3535
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class InteractionSettings(
5555
}
5656

5757
// Point scan
58-
override val strictRayCast by c.setting("Strict Raycast", true, "Whether to include the environment to the ray cast context", vis)
58+
override val strictRayCast by c.setting("Strict Raycast", false, "Whether to include the environment to the ray cast context", vis)
5959
override val checkSideVisibility by c.setting("Visibility Check", true, "Whether to check if an AABB side is visible", vis)
6060
override val resolution by c.setting("Resolution", 5, 1..20, 1, "The amount of grid divisions per surface of the hit box", "", vis)
6161
override val pointSelection by c.setting("Point Selection", PointSelection.Optimum, "The strategy to select the best hit point", vis)

common/src/main/kotlin/com/lambda/interaction/request/RequestHandler.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ abstract class RequestHandler<R : Request>(
6262

6363
listen<TickEvent.Post>(Int.MIN_VALUE) {
6464
activeThisTick = false
65+
queuedRequest = null
6566
}
6667

6768
return super.load()

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import com.lambda.interaction.request.placing.PlaceManager
4747
import com.lambda.interaction.request.rotation.RotationRequest
4848
import com.lambda.threading.runSafe
4949
import com.lambda.util.BlockUtils.blockState
50+
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
5051
import com.lambda.util.Communication.warn
5152
import com.lambda.util.item.ItemUtils.block
5253
import com.lambda.util.player.gamemode
@@ -227,7 +228,12 @@ object BreakManager : RequestHandler<BreakRequest>(
227228
.forEach { info ->
228229
if (info.updatedProgressThisTick) return@forEach
229230
val minKeepTicks = if (info.isSecondary) {
230-
val breakDelta = info.context.checkedState.calcBlockBreakingDelta(player, world, info.context.expectedPos)
231+
val breakDelta = info.context.checkedState.calcItemBlockBreakingDelta(
232+
player,
233+
world,
234+
info.context.expectedPos,
235+
player.inventory.getStack(info.context.hotbarIndex)
236+
)
231237
val breakAmount = breakDelta * (info.breakingTicks + 1)
232238
if (breakAmount >= 1.0f) 1 else 0
233239
} else 0

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ object HotbarManager : RequestHandler<HotbarRequest>(
5858
override fun load(): String {
5959
super.load()
6060

61-
listen<TickEvent.Pre>(priority = Int.MAX_VALUE) {
62-
activeRequest?.let { activeInfo ->
63-
if (activeInfo.keepTicks <= 0) {
64-
activeRequest = null
65-
}
66-
}
67-
}
68-
6961
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
7062
swapsThisTick = 0
7163
if (swapDelay > 0) swapDelay--
@@ -90,18 +82,29 @@ object HotbarManager : RequestHandler<HotbarRequest>(
9082

9183
if (tickStage !in config.sequenceStageMask) return
9284

93-
if (request.slot != activeRequest?.slot) {
94-
if (swapsThisTick + 1 > maxSwapsThisTick || swapDelay > 0) return
85+
val sameButLonger = activeRequest?.let { active ->
86+
request.slot == active.slot && request.keepTicks >= active.keepTicks
87+
} ?: false
88+
89+
if (sameButLonger) activeRequest?.let { current ->
90+
request.swapPauseAge = current.swapPauseAge
91+
} else run swap@ {
92+
if (request.slot != activeRequest?.slot) {
93+
if (swapsThisTick + 1 > maxSwapsThisTick || swapDelay > 0) return
94+
95+
activeRequest?.let { current ->
96+
if (current.swappedThisTick && current.keeping) return
97+
}
98+
99+
swapsThisTick++
100+
swapDelay = config.swapDelay
101+
return@swap
102+
}
95103

96104
activeRequest?.let { current ->
105+
request.swapPauseAge = current.swapPauseAge
97106
if (current.swappedThisTick && current.keeping) return
98107
}
99-
100-
swapsThisTick++
101-
swapDelay = config.swapDelay
102-
} else activeRequest?.let { current ->
103-
request.swapPauseAge = current.swapPauseAge
104-
if (current.swappedThisTick && current.keeping) return
105108
}
106109

107110
activeRequest = request
@@ -111,12 +114,11 @@ object HotbarManager : RequestHandler<HotbarRequest>(
111114

112115
private fun SafeContext.checkResetSwap() {
113116
activeRequest?.let { activeInfo ->
114-
if (activeInfo.keepTicks > 0) return
115-
116-
if (tickStage in activeInfo.hotbar.sequenceStageMask) {
117+
val canStopSwap = swapsThisTick < maxSwapsThisTick
118+
if (activeInfo.keepTicks <= 0 && tickStage in activeInfo.hotbar.sequenceStageMask && canStopSwap) {
119+
activeRequest = null
117120
interaction.syncSelectedSlot()
118121
}
119-
activeRequest = null
120122
}
121123
}
122124

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ object PacketMine : Module(
8585
attackedThisTick = false
8686
}
8787

88-
//ToDo: run on every tick stage
89-
listen<TickEvent.Pre> {
90-
if (!breakConfig.reBreak || (reBreakMode != ReBreakMode.Auto && reBreakMode != ReBreakMode.AutoConstant)) return@listen
91-
val reBreak = reBreakPos ?: return@listen
92-
requestBreakManager(listOf(reBreak), true)
93-
}
94-
9588
listen<PlayerEvent.Attack.Block> { it.cancel() }
9689
listen<PlayerEvent.Breaking.Update> { event ->
9790
event.cancel()
@@ -124,7 +117,12 @@ object PacketMine : Module(
124117
}
125118

126119
listen<TickEvent.Input.Post> {
127-
if (!attackedThisTick) requestBreakManager((breakPositions + queueSorted).toList())
120+
if (!attackedThisTick) {
121+
requestBreakManager((breakPositions + queueSorted).toList())
122+
if (!breakConfig.reBreak || (reBreakMode != ReBreakMode.Auto && reBreakMode != ReBreakMode.AutoConstant)) return@listen
123+
val reBreak = reBreakPos ?: return@listen
124+
requestBreakManager(listOf(reBreak), true)
125+
}
128126
}
129127

130128
onDisable {

common/src/main/kotlin/com/lambda/threading/Threading.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import java.util.concurrent.CompletableFuture
4242
* @return The result of the block execution if the context is safe, null otherwise.
4343
*/
4444
inline fun <T> runSafe(block: SafeContext.() -> T) =
45-
ClientContext().toSafe()?.let { block(it) }
45+
ClientContext().toSafe()?.run(block)
4646

4747
/**
4848
* This function is used to execute a block of code on a new thread running asynchronously to the game thread.

0 commit comments

Comments
 (0)