Skip to content

Commit 2bc6ef4

Browse files
committed
Fix BuildTask placing timings
1 parent a2de9ce commit 2bc6ef4

File tree

6 files changed

+30
-43
lines changed

6 files changed

+30
-43
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ object RotationManager : Loadable {
6363
fun Any.rotate(
6464
priority: Int = 0,
6565
alwaysListen: Boolean = false,
66-
block: RequestRotationBuilder.() -> Unit,
66+
block: RotationRequestBuilder.() -> Unit,
6767
) {
68-
val builder = RequestRotationBuilder().apply(block)
68+
val builder = RotationRequestBuilder().apply(block)
6969
var lastRequest: RotationRequest? = null
7070

7171
listen<RotationEvent.Update>(priority, alwaysListen) { event ->
72-
val rotationRequest = builder.onUpdate?.invoke(this, event.request)
72+
val rotationRequest = builder.request?.invoke(this, event.request)
7373

7474
rotationRequest?.let {
7575
event.request = it
@@ -80,26 +80,26 @@ object RotationManager : Loadable {
8080

8181
listen<RotationEvent.Post> { event ->
8282
if (event.request == lastRequest) {
83-
builder.onReceive?.invoke(this, event.request)
83+
builder.onFinish?.invoke(this, event.request)
8484
}
8585
}
8686
}
8787

8888
@DslMarker
8989
annotation class RotationDsl
9090

91-
class RequestRotationBuilder {
92-
var onUpdate: (SafeContext.(lastContext: RotationRequest?) -> RotationRequest?)? = null
93-
var onReceive: (SafeContext.(context: RotationRequest) -> Unit)? = null
91+
class RotationRequestBuilder {
92+
var request: (SafeContext.(lastContext: RotationRequest?) -> RotationRequest?)? = null
93+
var onFinish: (SafeContext.(context: RotationRequest) -> Unit)? = null
9494

9595
@RotationDsl
96-
fun onUpdate(block: SafeContext.(lastContext: RotationRequest?) -> RotationRequest?) {
97-
onUpdate = block
96+
fun request(block: SafeContext.(lastContext: RotationRequest?) -> RotationRequest?) {
97+
request = block
9898
}
9999

100100
@RotationDsl
101-
fun onReceive(block: SafeContext.(context: RotationRequest) -> Unit) {
102-
onReceive = block
101+
fun finished(block: SafeContext.(context: RotationRequest) -> Unit) {
102+
onFinish = block
103103
}
104104
}
105105

common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ object KillAura : Module(
115115

116116
init {
117117
rotate {
118-
onUpdate {
119-
if (!rotate) return@onUpdate null
118+
request {
119+
if (!rotate) return@request null
120120

121121
target?.let { target ->
122122
buildRotation(target)

common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ object Speed : Module(
135135
}
136136

137137
rotate(100, alwaysListen = false) {
138-
onUpdate { lastContext ->
139-
if (mode != Mode.GRIM_STRAFE) return@onUpdate null
140-
if (!shouldWork()) return@onUpdate null
138+
request { lastContext ->
139+
if (mode != Mode.GRIM_STRAFE) return@request null
140+
if (!shouldWork()) return@request null
141141

142142
var yaw = player.yaw
143143
val input = newMovementInput()
144144

145-
if (!input.isInputting) return@onUpdate null
145+
if (!input.isInputting) return@request null
146146

147147
run {
148148
if (!diagonal) return@run

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ object Scaffold : Module(
124124

125125
init {
126126
rotate {
127-
onUpdate {
127+
request {
128128
lastRotation = null
129-
val info = updatePlaceInfo() ?: return@onUpdate null
130-
val rotation = rotate(info) ?: return@onUpdate null
129+
val info = updatePlaceInfo() ?: return@request null
130+
val rotation = rotate(info) ?: return@request null
131131

132132
RotationRequest(rotation, rotationConfig)
133133
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ class BreakBlock @Ta5kBuilder constructor(
8181

8282
init {
8383
rotate {
84-
onUpdate {
85-
if (state != State.BREAKING) return@onUpdate null
86-
if (!rotate || ctx.instantBreak) return@onUpdate null
84+
request {
85+
if (state != State.BREAKING) return@request null
86+
if (!rotate || ctx.instantBreak) return@request null
8787

8888
lookAtBlock(blockPos, rotation, interact, sides)
8989
}
90-
onReceive { context ->
90+
finished { context ->
9191
isValid = context.isValid
9292
}
9393
}

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ import com.lambda.task.Task
4343
import com.lambda.util.BaritoneUtils
4444
import com.lambda.util.BlockUtils
4545
import com.lambda.util.BlockUtils.blockState
46-
import com.lambda.util.Communication.info
4746
import com.lambda.util.Formatting.string
47+
import com.lambda.util.collections.LimitedDecayQueue
4848
import com.lambda.util.extension.Structure
4949
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket
5050
import net.minecraft.util.math.BlockPos
51-
import java.util.concurrent.ConcurrentLinkedQueue
5251

5352
class BuildTask @Ta5kBuilder constructor(
5453
private val blueprint: Blueprint,
@@ -60,35 +59,24 @@ class BuildTask @Ta5kBuilder constructor(
6059
) : Task<Unit>() {
6160
override val name: String get() = "Building $blueprint with ${(placements / (age / 20.0 + 0.001)).string} p/s"
6261

63-
private val pendingPlacements = ConcurrentLinkedQueue<PlaceContext>()
64-
private val pendingBreaks = ConcurrentLinkedQueue<BreakContext>()
62+
private val pendingPlacements = LimitedDecayQueue<PlaceContext>(20, 1000)
63+
private val pendingBreaks = LimitedDecayQueue<BreakContext>(20, 1000)
6564

6665
private var currentPlacement: PlaceContext? = null
6766
private var placements = 0
6867
private var breaks = 0
69-
private var inScope = 0
7068

7169
override fun SafeContext.onStart() {
7270
(blueprint as? DynamicBlueprint)?.create()
7371
}
7472

7573
init {
7674
listen<TickEvent.Pre> {
77-
pendingPlacements.removeIf {
78-
val timeout = (mc.uptimeInTicks - it.placeTick) > build.placeTimeout
79-
if (timeout) {
80-
info("Placement Timeout of ${it.expectedPos.toShortString()}")
81-
}
82-
timeout
83-
}
84-
8575
currentPlacement?.let { context ->
86-
if (!context.rotation.isValid) return@listen
87-
if (inScope++ < 1) return@listen // ToDo: Should not be needed but timings are wrong
76+
if (!context.rotation.isValid) return@let
8877
context.place(interact.swingHand)
8978
pendingPlacements.add(context)
9079
currentPlacement = null
91-
inScope = 0
9280
}
9381

9482
(blueprint as? DynamicBlueprint)?.update()
@@ -161,9 +149,8 @@ class BuildTask @Ta5kBuilder constructor(
161149
}
162150

163151
rotate {
164-
onUpdate {
165-
if (currentPlacement == null) return@onUpdate null
166-
if (!build.rotateForPlace) return@onUpdate null
152+
request {
153+
if (!build.rotateForPlace) return@request null
167154
currentPlacement?.rotation
168155
}
169156
}

0 commit comments

Comments
 (0)