Skip to content

Commit bc883f8

Browse files
committed
return foreach instead of run and remove context sorting from the managers
1 parent 3df3485 commit bc883f8

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.lambda.graphics.renderer.esp.DirectionMask
2323
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2424
import com.lambda.interaction.construction.verify.TargetState
2525
import com.lambda.interaction.request.breaking.BreakRequest
26+
import com.lambda.interaction.request.hotbar.HotbarManager
2627
import com.lambda.interaction.request.hotbar.HotbarRequest
2728
import com.lambda.interaction.request.rotation.RotationRequest
2829
import com.lambda.util.world.raycast.RayCastUtils.distanceTo
@@ -64,8 +65,12 @@ data class BreakContext(
6465
return when (other) {
6566
is BreakContext -> compareByDescending<BreakContext> {
6667
if (it.checkedState.block is FallingBlock) it.expectedPos.y else 0
68+
}.thenBy {
69+
it.instantBreak
6770
}.thenBy {
6871
it.rotation.target.angleDistance
72+
}.thenBy {
73+
it.hotbarIndex == HotbarManager.serverSlot
6974
}.compare(this, other)
7075

7176
else -> 1

common/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

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

1818
package com.lambda.interaction.construction.context
1919

20+
import com.lambda.Lambda.mc
2021
import com.lambda.config.groups.BuildConfig
2122
import com.lambda.context.SafeContext
2223
import com.lambda.graphics.renderer.esp.DirectionMask
2324
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2425
import com.lambda.interaction.construction.verify.TargetState
26+
import com.lambda.interaction.request.hotbar.HotbarManager
2527
import com.lambda.interaction.request.hotbar.HotbarRequest
2628
import com.lambda.interaction.request.placing.PlaceRequest
2729
import com.lambda.interaction.request.rotation.RotationRequest
@@ -57,9 +59,11 @@ data class PlaceContext(
5759
}.thenByDescending {
5860
it.checkedState.fluidState.level
5961
}.thenBy {
60-
it.sneak
62+
it.sneak == mc.player?.isSneaking
6163
}.thenBy {
6264
it.rotation.target.angleDistance
65+
}.thenBy {
66+
it.hotbarIndex == HotbarManager.serverSlot
6367
}.thenBy {
6468
it.distance
6569
}.thenBy {
@@ -79,7 +83,7 @@ data class PlaceContext(
7983
fun requestDependencies(request: PlaceRequest): Boolean {
8084
val hotbarRequest = request.hotbar.request(HotbarRequest(hotbarIndex, request.hotbar))
8185
val validRotation = if (request.build.placing.rotate) {
82-
request.rotation.request(rotation, false).done && (!currentDirIsInvalid || rotation.matchesServerRot)
86+
request.rotation.request(rotation, false).done && !currentDirIsInvalid
8387
} else true
8488
return hotbarRequest.done && validRotation
8589
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import com.lambda.interaction.request.breaking.BrokenBlockHandler.destroyBlock
4242
import com.lambda.interaction.request.breaking.BrokenBlockHandler.pendingBreaks
4343
import com.lambda.interaction.request.breaking.BrokenBlockHandler.setPendingConfigs
4444
import com.lambda.interaction.request.breaking.BrokenBlockHandler.startPending
45-
import com.lambda.interaction.request.hotbar.HotbarManager
4645
import com.lambda.interaction.request.placing.PlaceManager
4746
import com.lambda.interaction.request.rotation.RotationRequest
4847
import com.lambda.threading.runSafe
@@ -199,7 +198,7 @@ object BreakManager : RequestHandler<BreakRequest>(
199198
}
200199
.asReversed()
201200
.forEach { info ->
202-
if (info.updatedProgressThisTick) return@run
201+
if (info.updatedProgressThisTick) return@forEach
203202
if (!info.context.requestDependencies(request)) return@run
204203
if ((!rotated && info.isPrimary) || tickStage !in info.breakConfig.breakStageMask) return@run
205204

@@ -216,7 +215,7 @@ object BreakManager : RequestHandler<BreakRequest>(
216215
}
217216

218217
/**
219-
* Filters and sorts the requests [BreakContext]s, and iterates over the [breakInfos] collection looking for matches
218+
* Filters the requests [BreakContext]s, and iterates over the [breakInfos] collection looking for matches
220219
* in positions. If a match is found, the [BreakInfo] is updated with the new context. Otherwise, the break is cancelled.
221220
* The [instantBreaks] and [breaks] collections are then populated with the new appropriate contexts, and the [maxBreaksThisTick]
222221
* value is set.
@@ -225,13 +224,10 @@ object BreakManager : RequestHandler<BreakRequest>(
225224
* @see cancelBreak
226225
*/
227226
private fun SafeContext.populateFrom(request: BreakRequest) {
228-
// Sanitize and sort the new breaks
227+
// Sanitize the new breaks
229228
val newBreaks = request.contexts
230229
.filter { ctx -> canAccept(ctx) }
231-
.sortedWith(
232-
compareByDescending<BreakContext> { it.instantBreak }
233-
.thenByDescending { it.hotbarIndex == HotbarManager.serverSlot }
234-
).toMutableList()
230+
.toMutableList()
235231

236232
// Update the current break infos or cancel if abandoned
237233
breakInfos

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import com.lambda.interaction.request.PositionBlocking
3030
import com.lambda.interaction.request.Priority
3131
import com.lambda.interaction.request.RequestHandler
3232
import com.lambda.interaction.request.breaking.BreakManager
33-
import com.lambda.interaction.request.hotbar.HotbarManager
3433
import com.lambda.interaction.request.placing.PlaceManager.activeRequest
3534
import com.lambda.interaction.request.placing.PlaceManager.processRequest
3635
import com.lambda.interaction.request.placing.PlacedBlockHandler.addPendingPlace
@@ -134,7 +133,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
134133

135134
if (ctx.sneak) shouldSneak = true
136135
if (!ctx.requestDependencies(request) || !validSneak(player)) return
137-
if (tickStage !in request.build.placing.placeStageMask) return
136+
// if (tickStage !in request.build.placing.placeStageMask) return
138137

139138
val actionResult = placeBlock(ctx, request, Hand.MAIN_HAND)
140139
if (!actionResult.isAccepted) warn("Placement interaction failed with $actionResult")
@@ -145,21 +144,18 @@ object PlaceManager : RequestHandler<PlaceRequest>(
145144
}
146145

147146
/**
148-
* Filters and sorts the [request]'s [PlaceContext]s, placing them into the [potentialPlacements] collection, and
147+
* Filters the [request]'s [PlaceContext]s, placing them into the [potentialPlacements] collection, and
149148
* setting the maxPlacementsThisTick value.
150149
*
151150
* @see canPlace
152151
*/
153-
private fun SafeContext.populateFrom(request: PlaceRequest) {
152+
private fun populateFrom(request: PlaceRequest) {
154153
val place = request.build.placing
155154

156155
setPendingConfigs(request)
157156
potentialPlacements = request.contexts
158157
.filter { canPlace(it) }
159-
.sortedWith(
160-
compareByDescending<PlaceContext> { it.hotbarIndex == HotbarManager.serverSlot }
161-
.thenByDescending { it.sneak == player.isSneaking }
162-
).toMutableList()
158+
.toMutableList()
163159

164160
val pendingLimit = (place.maxPendingPlacements - pendingPlacements.size).coerceAtLeast(0)
165161
maxPlacementsThisTick = (place.placementsPerTick.coerceAtMost(pendingLimit))

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.lambda.task.tasks
1919

2020
import baritone.api.pathing.goals.GoalBlock
21-
import baritone.api.pathing.goals.GoalNear
2221
import com.lambda.Lambda.LOG
2322
import com.lambda.config.groups.BuildConfig
2423
import com.lambda.config.groups.InteractionConfig
@@ -56,7 +55,6 @@ import com.lambda.util.extension.Structure
5655
import com.lambda.util.extension.inventorySlots
5756
import com.lambda.util.item.ItemUtils.block
5857
import com.lambda.util.player.SlotUtils.hotbarAndStorage
59-
import com.lambda.util.world.toFastVec
6058
import net.minecraft.entity.ItemEntity
6159
import net.minecraft.util.math.BlockPos
6260
import java.util.concurrent.ConcurrentLinkedQueue

0 commit comments

Comments
 (0)