Skip to content

Commit 54cac3f

Browse files
committed
initial rework
1 parent 0a86b07 commit 54cac3f

Some content is hidden

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

43 files changed

+434
-835
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+
findContainersWithSpace(selection).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/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/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: 3 additions & 1 deletion
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
}

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)
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()) {

src/main/kotlin/com/lambda/interaction/construction/verify/TargetState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ sealed class TargetState() : StateMatcher {
8787
override fun getStack(pos: BlockPos) =
8888
with(automatedSafeContext) {
8989
findDisposable()?.stacks?.firstOrNull {
90-
it.item.block in inventoryConfig.disposables && it.item.block !in replace
90+
it.item in inventoryConfig.disposables && it.item.block !in replace
9191
} ?: ItemStack(Items.NETHERRACK)
9292
}
9393

@@ -114,7 +114,7 @@ sealed class TargetState() : StateMatcher {
114114
override fun getStack(pos: BlockPos) =
115115
with(automatedSafeContext) {
116116
findDisposable()?.stacks?.firstOrNull {
117-
it.item.block in inventoryConfig.disposables
117+
it.item in inventoryConfig.disposables
118118
} ?: ItemStack(Items.NETHERRACK)
119119
}
120120

src/main/kotlin/com/lambda/interaction/managers/inventory/InventoryConfig.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,36 @@
1818
package com.lambda.interaction.managers.inventory
1919

2020
import com.lambda.config.ISettingGroup
21+
import com.lambda.context.SafeContext
2122
import com.lambda.event.events.TickEvent
2223
import com.lambda.interaction.material.ContainerSelection
2324
import com.lambda.interaction.material.StackSelection
2425
import com.lambda.interaction.material.container.MaterialContainer
2526
import com.lambda.util.Describable
2627
import com.lambda.util.NamedEnum
27-
import net.minecraft.block.Block
28+
import net.minecraft.item.Item
2829

2930
interface InventoryConfig : ISettingGroup {
3031
val actionsPerSecond: Int
3132
val tickStageMask: Collection<TickEvent>
32-
val disposables: Collection<Block>
33+
val disposables: Collection<Item>
3334
val swapWithDisposables: Boolean
3435
val providerPriority: Priority
3536
val storePriority: Priority
3637

37-
val immediateAccessOnly: Boolean
3838
val accessShulkerBoxes: Boolean
39-
val accessEnderChest: Boolean
4039
val accessChests: Boolean
40+
val accessEnderChest: Boolean
4141
val accessStashes: Boolean
4242

4343
val containerSelection: ContainerSelection
4444
get() = ContainerSelection.selectContainer {
4545
val allowedContainers = buildSet {
4646
addAll(MaterialContainer.Rank.entries)
47-
if (!accessShulkerBoxes || immediateAccessOnly) remove(MaterialContainer.Rank.ShulkerBox)
48-
if (!accessEnderChest || immediateAccessOnly) remove(MaterialContainer.Rank.EnderChest)
49-
if (!accessChests || immediateAccessOnly) remove(MaterialContainer.Rank.Chest)
50-
if (!accessStashes || immediateAccessOnly) remove(MaterialContainer.Rank.Stash)
47+
if (!accessShulkerBoxes) remove(MaterialContainer.Rank.ShulkerBox)
48+
if (!accessEnderChest) remove(MaterialContainer.Rank.EnderChest)
49+
if (!accessChests) remove(MaterialContainer.Rank.Chest)
50+
if (!accessStashes) remove(MaterialContainer.Rank.Stash)
5151
}
5252
ofAnyType(*allowedContainers.toTypedArray())
5353
}
@@ -59,6 +59,7 @@ interface InventoryConfig : ISettingGroup {
5959
WithMinItems("With Min Items", "Pick containers with the fewest matching items (or least space) first; useful for topping off or clearing leftovers."),
6060
WithMaxItems("With Max Items", "Pick containers with the most matching items (or most space) first; ideal for bulk moves with fewer transfers.");
6161

62+
context(_: SafeContext)
6263
fun materialComparator(selection: StackSelection) =
6364
when (this) {
6465
WithMaxItems -> compareBy<MaterialContainer> { it.rank }
@@ -70,6 +71,7 @@ interface InventoryConfig : ISettingGroup {
7071
.thenBy { it.name }
7172
}
7273

74+
context(_: SafeContext)
7375
fun spaceComparator(selection: StackSelection) =
7476
when (this) {
7577
WithMaxItems -> compareBy<MaterialContainer> { it.rank }

src/main/kotlin/com/lambda/interaction/material/ContainerSelection.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class ContainerSelection {
3838
* which matches the given StackSelection.
3939
*/
4040
@ContainerSelectionDsl
41+
context(_: SafeContext)
4142
fun matches(stackSelection: StackSelection): (MaterialContainer) -> Boolean =
42-
{ container -> container.matchingStacks(stackSelection).isNotEmpty() }
43+
{ container -> container.matchingSlots(stackSelection).isNotEmpty() }
4344

4445
/**
4546
* Returns a function that checks whether a given MaterialContainer matches the criteria
@@ -63,11 +64,6 @@ class ContainerSelection {
6364
fun noneOfType(vararg types: MaterialContainer.Rank): (MaterialContainer) -> Boolean =
6465
{ container -> !types.contains(container.rank) }
6566

66-
@ContainerSelectionDsl
67-
context(_: SafeContext)
68-
fun immediateOnly(): (MaterialContainer) -> Boolean =
69-
{ container -> !container.isImmediatelyAccessible() }
70-
7167
/**
7268
* Returns a function that combines two container predicates using logical AND.
7369
*/

0 commit comments

Comments
 (0)