Skip to content

Commit bb9ea59

Browse files
committed
Merge branch '1.21.11' into improvement/bind-listeners
2 parents a597a9b + 4044077 commit bb9ea59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+594
-869
lines changed

src/main/kotlin/com/lambda/command/commands/TransferCommand.kt

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import com.lambda.interaction.material.StackSelection.Companion.selectStack
3232
import com.lambda.interaction.material.container.ContainerManager
3333
import com.lambda.interaction.material.container.ContainerManager.findContainersWithMaterial
3434
import com.lambda.interaction.material.container.ContainerManager.findContainersWithSpace
35-
import com.lambda.interaction.material.transfer.TransferResult
36-
import com.lambda.task.RootTask.run
37-
import com.lambda.threading.runSafe
35+
import com.lambda.task.RootTask
36+
import com.lambda.task.Task
37+
import com.lambda.threading.runSafeAutomated
3838
import com.lambda.util.Communication.info
3939
import com.lambda.util.extension.CommandBuilder
4040

@@ -43,7 +43,7 @@ object TransferCommand : LambdaCommand(
4343
usage = "transfer <move | cancel | undo> <item> <amount> <to>",
4444
description = "Transfer items from anywhere to anywhere",
4545
) {
46-
private var lastContainerTransfer: TransferResult.ContainerTransfer? = null
46+
private var lastContainerTransfer: Task<*>? = null
4747

4848
override fun CommandBuilder.create() {
4949
required(itemStack("stack", registry)) { stack ->
@@ -54,12 +54,10 @@ object TransferCommand : LambdaCommand(
5454
val selection = selectStack(count) {
5555
isItem(stack(ctx).value().item)
5656
}
57-
with(AutomationConfig.Companion.DEFAULT) {
58-
runSafe {
59-
selection.findContainersWithMaterial().forEachIndexed { i, container ->
60-
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
61-
}
62-
}
57+
AutomationConfig.Companion.DEFAULT.runSafeAutomated {
58+
selection.findContainersWithMaterial().forEachIndexed { i, container ->
59+
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
60+
}
6361
}
6462
builder.buildFuture()
6563
}
@@ -68,11 +66,9 @@ object TransferCommand : LambdaCommand(
6866
val selection = selectStack(amount(ctx).value()) {
6967
isItem(stack(ctx).value().item)
7068
}
71-
with(AutomationConfig.Companion.DEFAULT) {
72-
runSafe {
73-
findContainersWithSpace(selection).forEachIndexed { i, container ->
74-
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
75-
}
69+
AutomationConfig.Companion.DEFAULT.runSafeAutomated {
70+
selection.findContainersWithSpace().forEachIndexed { i, container ->
71+
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
7672
}
7773
}
7874
builder.buildFuture()
@@ -81,35 +77,17 @@ object TransferCommand : LambdaCommand(
8177
val selection = selectStack(amount().value()) {
8278
isItem(stack().value().item)
8379
}
84-
val fromContainer = ContainerManager.containers().find {
85-
it.name == from().value().split(".").last().trim()
86-
} ?: return@executeWithResult failure("From container not found")
80+
AutomationConfig.Companion.DEFAULT.runSafeAutomated {
81+
val fromContainer = ContainerManager.containers().find {
82+
it.name == from().value().split(".").last().trim()
83+
} ?: return@executeWithResult failure("From container not found")
8784

88-
val toContainer = ContainerManager.containers().find {
89-
it.name == to().value().split(".").last().trim()
90-
} ?: return@executeWithResult failure("To container not found")
85+
val toContainer = ContainerManager.containers().find {
86+
it.name == to().value().split(".").last().trim()
87+
} ?: return@executeWithResult failure("To container not found")
9188

92-
with(AutomationConfig.Companion.DEFAULT) {
93-
when (val transaction = fromContainer.transfer(selection, toContainer)) {
94-
is TransferResult.ContainerTransfer -> {
95-
info("${transaction.name} started.")
96-
lastContainerTransfer = transaction
97-
transaction.finally {
98-
info("${transaction.name} completed.")
99-
}.run()
100-
return@executeWithResult success()
101-
}
102-
103-
is TransferResult.MissingItems -> {
104-
return@executeWithResult failure("Missing items: ${transaction.missing}")
105-
}
106-
107-
is TransferResult.NoSpace -> {
108-
return@executeWithResult failure("No space in ${toContainer.name}")
109-
}
110-
}
89+
fromContainer.transferByTask(selection, toContainer).execute(RootTask)
11190
}
112-
11391
return@executeWithResult success()
11492
}
11593
}

src/main/kotlin/com/lambda/config/groups/BuildConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ interface BuildConfig : ISettingGroup {
3434
val actionTimeout: Int
3535
val maxBuildDependencies: Int
3636

37-
val entityReach: Double
3837
val blockReach: Double
38+
val entityReach: Double
3939
val scanReach: Double
4040

4141
val checkSideVisibility: Boolean

src/main/kotlin/com/lambda/config/groups/BuildSettings.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ class BuildSettings(
3636
override val breakBlocks by c.setting("Break", true, "Break blocks").group(baseGroup, Group.General).index()
3737
override val interactBlocks by c.setting("Place / Interact", true, "Interact blocks").group(baseGroup, Group.General).index()
3838

39-
override val pathing by c.setting("Pathing", true, "Path to blocks").group(baseGroup, Group.General).index()
40-
override val stayInRange by c.setting("Stay In Range", true, "Stay in range of blocks").group(baseGroup, Group.General).index()
39+
override val pathing by c.setting("Pathing", false, "Path to blocks").group(baseGroup, Group.General).index()
40+
override val stayInRange by c.setting("Stay In Range", false, "Stay in range of blocks").group(baseGroup, Group.General).index()
4141
override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks").group(baseGroup, Group.General).index()
4242
override val spleefEntities by c.setting("Spleef Entities", false, "Breaks blocks beneath entities blocking placements to get them out of the way").group(baseGroup, Group.General).index()
4343
override val maxPendingActions by c.setting("Max Pending Actions", 15, 1..30, 1, "The maximum count of pending interactions to allow before pausing future interactions").group(baseGroup, Group.General).index()
4444
override val actionTimeout by c.setting("Action Timeout", 10, 1..30, 1, "Timeout for block breaks in ticks", unit = " ticks").group(baseGroup, Group.General).index()
4545
override val maxBuildDependencies by c.setting("Max Sim Dependencies", 3, 0..10, 1, "Maximum dependency build results").group(baseGroup, Group.General).index()
4646

47-
override var entityReach by c.setting("Attack Reach", 3.0, 1.0..7.0, 0.01, "Maximum entity interaction distance").group(baseGroup, Group.Reach).index()
4847
override var blockReach by c.setting("Interact Reach", 4.5, 1.0..7.0, 0.01, "Maximum block interaction distance").group(baseGroup, Group.Reach).index()
48+
override var entityReach by c.setting("Attack Reach", 3.0, 1.0..7.0, 0.01, "Maximum entity interaction distance").group(baseGroup, Group.Reach).index()
4949
override val scanReach: Double get() = max(entityReach, blockReach)
5050

5151
override val checkSideVisibility by c.setting("Visibility Check", true, "Whether to check if an AABB side is visible").group(baseGroup, Group.Scan).index()

src/main/kotlin/com/lambda/config/groups/InventorySettings.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ class InventorySettings(
4141
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from").group(baseGroup, Group.Container).index()
4242
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when storing the item to").group(baseGroup, Group.Container).index()
4343

44-
override val immediateAccessOnly by c.setting("Immediate Access Only", false, "Only allow access to inventories that can be accessed immediately").group(baseGroup, Group.Access).index()
45-
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", true, "Allow access to the player's shulker boxes") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
46-
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
47-
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
48-
override val accessStashes by c.setting("Access Stashes", false, "Allow access to the player's stashes") { !immediateAccessOnly }.group(baseGroup, Group.Access).index()
44+
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", false, "Allow access to the player's shulker boxes").group(baseGroup, Group.Access).index()
45+
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests").group(baseGroup, Group.Access).index()
46+
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest").group(baseGroup, Group.Access).index()
47+
override val accessStashes by c.setting("Access Stashes", false, "Allow access to the player's stashes").group(baseGroup, Group.Access).index()
4948
}

src/main/kotlin/com/lambda/interaction/BaritoneManager.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import baritone.api.BaritoneAPI
2121
import baritone.api.IBaritone
2222
import baritone.api.Settings
2323
import baritone.api.pathing.goals.Goal
24+
import com.lambda.config.AutomationConfig
2425
import com.lambda.config.Configurable
2526
import com.lambda.config.configurations.LambdaConfig
2627
import com.lambda.config.groups.RotationSettings
2728
import com.lambda.context.Automated
28-
import com.lambda.config.AutomationConfig
2929
import com.lambda.util.BlockUtils.blockPos
3030
import com.lambda.util.NamedEnum
3131
import net.fabricmc.loader.api.FabricLoader
@@ -352,8 +352,10 @@ object BaritoneManager : Configurable(LambdaConfig), Automated by AutomationConf
352352
* Whether Baritone is active (pathing, calculating goal, etc.)
353353
*/
354354
val isActive: Boolean
355-
get() = isBaritoneLoaded && (primary?.customGoalProcess?.isActive == true || primary?.pathingBehavior?.isPathing == true || primary?.pathingControlManager?.mostRecentInControl()
356-
?.orElse(null)?.isActive == true)
355+
get() = isBaritoneLoaded &&
356+
(primary?.customGoalProcess?.isActive == true ||
357+
primary?.pathingBehavior?.isPathing == true ||
358+
primary?.pathingControlManager?.mostRecentInControl()?.orElse(null)?.isActive == true)
357359

358360
/**
359361
* Sets the current Baritone goal and starts pathing

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/BreakSim.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,9 @@ class BreakSim private constructor(simInfo: SimInfo)
185185
}
186186

187187
val hotbarCandidates = stackSelection
188-
.findContainersWithMaterial(silentSwapSelection)
189-
.map { it.matchingStacks(stackSelection) }
190-
.flatten()
191-
if (hotbarCandidates.isEmpty()) {
188+
.findContainersWithMaterial(silentSwapSelection)
189+
.flatMap { it.matchingStacks(stackSelection) }
190+
if (hotbarCandidates.isEmpty()) {
192191
result(GenericResult.WrongItemSelection(pos, stackSelection, player.mainHandStack))
193192
return null
194193
}

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/InteractSim.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import com.lambda.util.item.ItemUtils.blockItem
4747
import com.lambda.util.math.MathUtils.floorToInt
4848
import com.lambda.util.math.minus
4949
import com.lambda.util.player.MovementUtils.sneaking
50+
import com.lambda.util.player.SlotUtils.hotbarStacks
5051
import com.lambda.util.player.copyPlayer
5152
import com.lambda.util.world.raycast.RayCastUtils.blockResult
5253
import kotlinx.coroutines.CoroutineScope
@@ -223,8 +224,9 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
223224
result(GenericResult.WrongItemSelection(pos, stackSelection, player.mainHandStack))
224225
return null
225226
}
227+
val hotbarStacks = player.hotbarStacks
226228
return stackSelection.filterStacks(container.stacks).run {
227-
firstOrNull { it.inventoryIndex == player.inventory.selectedSlot }
229+
firstOrNull { hotbarStacks.indexOf(it) == player.inventory.selectedSlot }
228230
?: firstOrNull()
229231
}
230232
}
@@ -271,7 +273,7 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
271273
}
272274

273275
private suspend fun AutomatedSafeContext.testPlaceState(context: ItemPlacementContext): BlockState? {
274-
val resultState = context.stack.blockItem.getPlacementState(context)
276+
val resultState = (context.stack.blockItem ?: return null).getPlacementState(context)
275277
?: run {
276278
handleEntityBlockage(context)
277279
return null
@@ -285,7 +287,7 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
285287

286288
private suspend fun AutomatedSafeContext.handleEntityBlockage(context: ItemPlacementContext): List<Entity> {
287289
val pos = context.blockPos
288-
val theoreticalState = context.stack.blockItem.block.getPlacementState(context)
290+
val theoreticalState = (context.stack.blockItem ?: return emptyList()).block.getPlacementState(context)
289291
?: return emptyList()
290292

291293
val collisionShape = theoreticalState.getCollisionShape(

src/main/kotlin/com/lambda/interaction/construction/simulation/result/Resolvable.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
package com.lambda.interaction.construction.simulation.result
1919

20-
import com.lambda.context.Automated
21-
import com.lambda.context.SafeContext
20+
import com.lambda.context.AutomatedSafeContext
2221
import com.lambda.task.Task
2322

2423
/**
2524
* Represents a [BuildResult] with a resolvable [Task]
2625
*/
2726
interface Resolvable {
28-
context(automated: Automated, safeContext: SafeContext)
29-
fun resolve(): Task<*>?
27+
context(task: Task<*>, _: AutomatedSafeContext)
28+
fun resolve()
3029
}

src/main/kotlin/com/lambda/interaction/construction/simulation/result/results/BreakResult.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ package com.lambda.interaction.construction.simulation.result.results
1919

2020
import baritone.api.pathing.goals.GoalBlock
2121
import baritone.api.pathing.goals.GoalInverted
22-
import com.lambda.context.Automated
23-
import com.lambda.context.SafeContext
24-
import com.lambda.graphics.renderer.esp.DirectionMask.mask
25-
import com.lambda.graphics.esp.ShapeScope
22+
import com.lambda.context.AutomatedSafeContext
2623
import com.lambda.graphics.mc.TransientRegionESP
24+
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2725
import com.lambda.interaction.construction.simulation.context.BreakContext
2826
import com.lambda.interaction.construction.simulation.result.BuildResult
2927
import com.lambda.interaction.construction.simulation.result.ComparableResult
@@ -34,8 +32,9 @@ import com.lambda.interaction.construction.simulation.result.Navigable
3432
import com.lambda.interaction.construction.simulation.result.Rank
3533
import com.lambda.interaction.construction.simulation.result.Resolvable
3634
import com.lambda.interaction.material.StackSelection.Companion.selectStack
37-
import com.lambda.interaction.material.container.ContainerManager.transfer
38-
import com.lambda.interaction.material.container.containers.MainHandContainer
35+
import com.lambda.interaction.material.container.ContainerManager.transferByTask
36+
import com.lambda.interaction.material.container.containers.HotbarContainer
37+
import com.lambda.task.Task
3938
import net.minecraft.block.BlockState
4039
import net.minecraft.item.Item
4140
import net.minecraft.util.math.BlockPos
@@ -98,11 +97,12 @@ sealed class BreakResult : BuildResult() {
9897
) : Resolvable, BreakResult() {
9998
override val rank = Rank.BreakItemCantMine
10099

101-
context(automated: Automated, safeContext: SafeContext)
102-
override fun resolve() =
100+
context(task: Task<*>, _: AutomatedSafeContext)
101+
override fun resolve() {
103102
selectStack {
104103
isItem(badItem).not()
105-
}.transfer(MainHandContainer)
104+
}.transferByTask(HotbarContainer)?.execute(task)
105+
}
106106

107107
override fun compareResult(other: ComparableResult<Rank>) =
108108
when (other) {

src/main/kotlin/com/lambda/interaction/construction/simulation/result/results/GenericResult.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
package com.lambda.interaction.construction.simulation.result.results
1919

2020
import baritone.api.pathing.goals.GoalNear
21-
import com.lambda.context.Automated
22-
import com.lambda.context.SafeContext
23-
import com.lambda.graphics.esp.ShapeScope
21+
import com.lambda.context.AutomatedSafeContext
2422
import com.lambda.graphics.mc.TransientRegionESP
2523
import com.lambda.interaction.construction.simulation.result.BuildResult
2624
import com.lambda.interaction.construction.simulation.result.ComparableResult
@@ -29,8 +27,9 @@ import com.lambda.interaction.construction.simulation.result.Navigable
2927
import com.lambda.interaction.construction.simulation.result.Rank
3028
import com.lambda.interaction.construction.simulation.result.Resolvable
3129
import com.lambda.interaction.material.StackSelection
32-
import com.lambda.interaction.material.container.ContainerManager.transfer
33-
import com.lambda.interaction.material.container.containers.MainHandContainer
30+
import com.lambda.interaction.material.container.ContainerManager.transferByTask
31+
import com.lambda.interaction.material.container.containers.HotbarContainer
32+
import com.lambda.task.Task
3433
import net.minecraft.client.data.TextureMap.side
3534
import net.minecraft.item.ItemStack
3635
import net.minecraft.util.math.BlockPos
@@ -98,8 +97,10 @@ sealed class GenericResult : BuildResult() {
9897
override val rank = Rank.WrongItem
9998
private val color = Color(3, 252, 169, 25)
10099

101-
context(automated: Automated, safeContext: SafeContext)
102-
override fun resolve() = neededSelection.transfer(MainHandContainer)
100+
context(task: Task<*>, _: AutomatedSafeContext)
101+
override fun resolve() {
102+
neededSelection.transferByTask(HotbarContainer)?.execute(task)
103+
}
103104

104105
override fun render(esp: TransientRegionESP) {
105106
esp.shapes(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble()) {

0 commit comments

Comments
 (0)