Skip to content

Commit c37b72e

Browse files
committed
allow overriding the current queued request if the config matches and couple configs with requests
1 parent 4bef752 commit c37b72e

File tree

10 files changed

+19
-20
lines changed

10 files changed

+19
-20
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ enum class TickStage {
2121
TickStart,
2222
PostHotbar,
2323
PostInteract,
24-
PreMovement,
2524
PostMovement,
2625
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
package com.lambda.interaction.request
1919

2020
abstract class Request (
21-
val priority: Priority
21+
val priority: Priority,
22+
val config: RequestConfig<*>
2223
) {
2324
var fresh = true
2425

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ abstract class RequestHandler<R : Request>(
6262
TickStage.TickStart -> openRequestsFor<TickEvent.Pre>(TickStage.TickStart)
6363
TickStage.PostHotbar -> { /*ToDo*/ }
6464
TickStage.PostInteract -> { /*ToDo*/ }
65-
TickStage.PreMovement -> openRequestsFor<MovementEvent.Player.Pre>(TickStage.PreMovement)
6665
TickStage.PostMovement -> openRequestsFor<MovementEvent.Player.Post>(TickStage.PostMovement)
6766
}
6867
}
@@ -102,7 +101,8 @@ abstract class RequestHandler<R : Request>(
102101
*/
103102
fun request(request: R, queueIfClosed: Boolean = true): R {
104103
if (!acceptingRequests) {
105-
if (queueIfClosed && queuedRequest == null) {
104+
val canOverrideQueued = queuedRequest?.run { config === request.config } ?: true
105+
if (queueIfClosed && canOverrideQueued) {
106106
queuedRequest = request
107107
}
108108
return request

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ data class BreakRequest(
4040
val onBreak: ((BlockPos) -> Unit)? = null,
4141
val onItemDrop: ((ItemEntity) -> Unit)? = null,
4242
private val prio: Priority = 0
43-
) : Request(prio) {
43+
) : Request(prio, build.breaking) {
4444
override val done: Boolean
4545
get() = runSafe {
4646
contexts.all {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ object HotbarManager : RequestHandler<HotbarRequest>(
7777
}
7878

7979
override fun SafeContext.handleRequest(request: HotbarRequest) {
80-
val hotbarConfig = request.hotbarConfig
81-
maxSwapsThisTick = hotbarConfig.swapsPerTick
82-
swapDelay = swapDelay.coerceAtMost(hotbarConfig.swapDelay)
80+
val hotbar = request.hotbar
81+
maxSwapsThisTick = hotbar.swapsPerTick
82+
swapDelay = swapDelay.coerceAtMost(hotbar.swapDelay)
8383

84-
if (tickStage !in hotbarConfig.sequenceStageMask) return
84+
if (tickStage !in hotbar.sequenceStageMask) return
8585

8686
if (request.slot != activeRequest?.slot) {
8787
if (swapsThisTick + 1 > maxSwapsThisTick || swapDelay > 0) return
@@ -91,7 +91,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
9191
}
9292

9393
swapsThisTick++
94-
swapDelay = hotbarConfig.swapDelay
94+
swapDelay = hotbar.swapDelay
9595
} else activeRequest?.let { current ->
9696
request.swapPauseAge = current.swapPauseAge
9797
if (current.swappedThisTick && current.keeping) return

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import com.lambda.interaction.request.Request
2222

2323
class HotbarRequest(
2424
val slot: Int,
25-
val hotbarConfig: HotbarConfig,
26-
var keepTicks: Int = hotbarConfig.keepTicks,
27-
var swapPause: Int = hotbarConfig.swapPause,
25+
val hotbar: HotbarConfig,
26+
var keepTicks: Int = hotbar.keepTicks,
27+
var swapPause: Int = hotbar.swapPause,
2828
priority: Priority = 0,
29-
) : Request(priority) {
29+
) : Request(priority, hotbar) {
3030
var activeRequestAge = 0
3131
var swapPauseAge = 0
3232

common/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
173173
if (!request.rotation.rotate) return
174174

175175
// In case you cant rotate and place within the same tick
176-
potentialPlacements.getOrNull(maxPlacementsThisTick)?.let { nextPredictedPlacement ->
176+
potentialPlacements.getOrNull(maxPlacementsThisTick - 1)?.let { nextPredictedPlacement ->
177177
request.rotation.request(nextPredictedPlacement.rotation)
178178
}
179179
}

common/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data class PlaceRequest(
3535
val pendingInteractions: MutableCollection<BuildContext>,
3636
val prio: Priority = 0,
3737
val onPlace: () -> Unit
38-
) : Request(prio) {
38+
) : Request(prio, build.placing) {
3939
override val done: Boolean
4040
get() = runSafe {
4141
contexts.all { it.targetState.matches(blockState(it.expectedPos), it.expectedPos, world) }

common/src/main/kotlin/com/lambda/interaction/request/rotation/RotationManager.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import kotlin.math.sign
5151
import kotlin.math.sin
5252

5353
object RotationManager : RequestHandler<RotationRequest>(
54-
TickStage.PreMovement,
54+
TickStage.TickStart,
5555
preOpen = { preEvent() }
5656
), Loadable {
5757
var currentRotation = Rotation.ZERO
@@ -70,7 +70,6 @@ object RotationManager : RequestHandler<RotationRequest>(
7070
block()
7171
}
7272

73-
7473
init {
7574
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
7675
activeRequest?.let { request ->

common/src/main/kotlin/com/lambda/interaction/request/rotation/RotationRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ data class RotationRequest(
2626
val target: RotationTarget,
2727
val prio: Priority,
2828
val mode: RotationMode,
29-
val rotationConfig: RotationConfig,
29+
val rot: RotationConfig,
3030
var keepTicks: Int = 3,
3131
var decayTicks: Int = 0,
3232
val turnSpeed: () -> Double = { 180.0 },
3333
val speedMultiplier: Double = 1.0
34-
) : Request(prio) {
34+
) : Request(prio, rot) {
3535
var age = 0
3636

3737
constructor(

0 commit comments

Comments
 (0)