Skip to content

Commit 5bf9469

Browse files
committed
immediateAccessOnly setting in inventory settings
1 parent 88ee101 commit 5bf9469

File tree

22 files changed

+94
-55
lines changed

22 files changed

+94
-55
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import com.lambda.command.LambdaCommand
3030
import com.lambda.config.AutomationConfig
3131
import com.lambda.interaction.material.StackSelection.Companion.selectStack
3232
import com.lambda.interaction.material.container.ContainerManager
33-
import com.lambda.interaction.material.container.ContainerManager.containerWithMaterial
34-
import com.lambda.interaction.material.container.ContainerManager.containerWithSpace
33+
import com.lambda.interaction.material.container.ContainerManager.findContainersWithMaterial
34+
import com.lambda.interaction.material.container.ContainerManager.findContainersWithSpace
3535
import com.lambda.interaction.material.transfer.TransferResult
3636
import com.lambda.task.RootTask.run
37+
import com.lambda.threading.runSafe
3738
import com.lambda.util.Communication.info
3839
import com.lambda.util.extension.CommandBuilder
3940

@@ -54,8 +55,10 @@ object TransferCommand : LambdaCommand(
5455
isItem(stack(ctx).value().item)
5556
}
5657
with(AutomationConfig.Companion.DEFAULT) {
57-
selection.containerWithMaterial().forEachIndexed { i, container ->
58-
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
58+
runSafe {
59+
selection.findContainersWithMaterial().forEachIndexed { i, container ->
60+
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
61+
}
5962
}
6063
}
6164
builder.buildFuture()
@@ -66,8 +69,10 @@ object TransferCommand : LambdaCommand(
6669
isItem(stack(ctx).value().item)
6770
}
6871
with(AutomationConfig.Companion.DEFAULT) {
69-
containerWithSpace(selection).forEachIndexed { i, container ->
70-
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
72+
runSafe {
73+
findContainersWithSpace(selection).forEachIndexed { i, container ->
74+
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
75+
}
7176
}
7277
}
7378
builder.buildFuture()
@@ -76,11 +81,11 @@ object TransferCommand : LambdaCommand(
7681
val selection = selectStack(amount().value()) {
7782
isItem(stack().value().item)
7883
}
79-
val fromContainer = ContainerManager.container().find {
84+
val fromContainer = ContainerManager.containers().find {
8085
it.name == from().value().split(".").last().trim()
8186
} ?: return@executeWithResult failure("From container not found")
8287

83-
val toContainer = ContainerManager.container().find {
88+
val toContainer = ContainerManager.containers().find {
8489
it.name == to().value().split(".").last().trim()
8590
} ?: return@executeWithResult failure("To container not found")
8691

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ 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()
4445
override val accessShulkerBoxes by c.setting("Access Shulker Boxes", true, "Allow access to the player's shulker boxes").group(baseGroup, Group.Access).index()
4546
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest").group(baseGroup, Group.Access).index()
4647
override val accessChests by c.setting("Access Chests", false, "Allow access to the player's normal chests").group(baseGroup, Group.Access).index()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import com.lambda.interaction.material.ContainerSelection.Companion.selectContai
3232
import com.lambda.interaction.material.StackSelection
3333
import com.lambda.interaction.material.StackSelection.Companion.EVERYTHING
3434
import com.lambda.interaction.material.StackSelection.Companion.selectStack
35-
import com.lambda.interaction.material.container.ContainerManager.containerWithMaterial
35+
import com.lambda.interaction.material.container.ContainerManager.findContainersWithMaterial
3636
import com.lambda.interaction.material.container.MaterialContainer
3737
import com.lambda.interaction.managers.hotbar.HotbarManager
3838
import com.lambda.interaction.managers.rotating.RotationManager
@@ -187,7 +187,7 @@ class BreakSim private constructor(simInfo: SimInfo)
187187
}
188188

189189
val hotbarCandidates = stackSelection
190-
.containerWithMaterial(silentSwapSelection)
190+
.findContainersWithMaterial(silentSwapSelection)
191191
.map { it.matchingStacks(stackSelection) }
192192
.flatten()
193193
if (hotbarCandidates.isEmpty()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import com.lambda.interaction.managers.rotating.visibilty.lookInDirection
3838
import com.lambda.interaction.material.ContainerSelection.Companion.selectContainer
3939
import com.lambda.interaction.material.StackSelection
4040
import com.lambda.interaction.material.StackSelection.Companion.select
41-
import com.lambda.interaction.material.container.ContainerManager.containerWithMaterial
41+
import com.lambda.interaction.material.container.ContainerManager.findContainersWithMaterial
4242
import com.lambda.interaction.material.container.MaterialContainer
4343
import com.lambda.util.BlockUtils
4444
import com.lambda.util.BlockUtils.blockState
@@ -219,7 +219,7 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
219219
val stackSelection = item?.select()
220220
?: StackSelection.selectStack(0, sorter = compareByDescending { it.inventoryIndex == player.inventory.selectedSlot })
221221
val containerSelection = selectContainer { ofAnyType(MaterialContainer.Rank.Hotbar) }
222-
val container = stackSelection.containerWithMaterial(containerSelection).firstOrNull() ?: run {
222+
val container = stackSelection.findContainersWithMaterial(containerSelection).firstOrNull() ?: run {
223223
result(GenericResult.WrongItemSelection(pos, stackSelection, player.mainHandStack))
224224
return null
225225
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
package com.lambda.interaction.construction.simulation.result
1919

2020
import com.lambda.context.Automated
21+
import com.lambda.context.SafeContext
2122
import com.lambda.task.Task
2223

2324
/**
2425
* Represents a [BuildResult] with a resolvable [Task]
2526
*/
2627
interface Resolvable {
27-
context(automated: Automated)
28-
fun resolve(): Task<*>
28+
context(automated: Automated, safeContext: SafeContext)
29+
fun resolve(): Task<*>?
2930
}

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.lambda.interaction.construction.simulation.result.results
2020
import baritone.api.pathing.goals.GoalBlock
2121
import baritone.api.pathing.goals.GoalInverted
2222
import com.lambda.context.Automated
23+
import com.lambda.context.SafeContext
2324
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2425
import com.lambda.graphics.renderer.esp.ShapeBuilder
2526
import com.lambda.interaction.construction.simulation.context.BreakContext
@@ -33,7 +34,6 @@ import com.lambda.interaction.construction.simulation.result.Rank
3334
import com.lambda.interaction.construction.simulation.result.Resolvable
3435
import com.lambda.interaction.material.StackSelection.Companion.selectStack
3536
import com.lambda.interaction.material.container.ContainerManager.transfer
36-
import com.lambda.interaction.material.container.MaterialContainer
3737
import com.lambda.interaction.material.container.containers.MainHandContainer
3838
import net.minecraft.block.BlockState
3939
import net.minecraft.item.Item
@@ -95,18 +95,11 @@ sealed class BreakResult : BuildResult() {
9595
) : Resolvable, BreakResult() {
9696
override val rank = Rank.BreakItemCantMine
9797

98-
context(automated: Automated)
98+
context(automated: Automated, safeContext: SafeContext)
9999
override fun resolve() =
100100
selectStack {
101101
isItem(badItem).not()
102-
}.let { selection ->
103-
selection.transfer(MainHandContainer)
104-
?: MaterialContainer.AwaitItemTask(
105-
"Couldn't find a tool for ${blockState.block.name.string} with $badItem in main hand.",
106-
selection,
107-
automated
108-
)
109-
}
102+
}.transfer(MainHandContainer)
110103

111104
override fun compareResult(other: ComparableResult<Rank>) =
112105
when (other) {

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

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

2020
import baritone.api.pathing.goals.GoalNear
2121
import com.lambda.context.Automated
22+
import com.lambda.context.SafeContext
2223
import com.lambda.graphics.renderer.esp.ShapeBuilder
2324
import com.lambda.interaction.construction.simulation.result.BuildResult
2425
import com.lambda.interaction.construction.simulation.result.ComparableResult
@@ -28,7 +29,6 @@ import com.lambda.interaction.construction.simulation.result.Rank
2829
import com.lambda.interaction.construction.simulation.result.Resolvable
2930
import com.lambda.interaction.material.StackSelection
3031
import com.lambda.interaction.material.container.ContainerManager.transfer
31-
import com.lambda.interaction.material.container.MaterialContainer
3232
import com.lambda.interaction.material.container.containers.MainHandContainer
3333
import net.minecraft.client.data.TextureMap.side
3434
import net.minecraft.item.ItemStack
@@ -95,14 +95,8 @@ sealed class GenericResult : BuildResult() {
9595
override val rank = Rank.WrongItem
9696
private val color = Color(3, 252, 169, 25)
9797

98-
context(automated: Automated)
99-
override fun resolve() =
100-
neededSelection.transfer(MainHandContainer)
101-
?: MaterialContainer.AwaitItemTask(
102-
"Couldn't find $neededSelection anywhere.",
103-
neededSelection,
104-
automated
105-
)
98+
context(automated: Automated, safeContext: SafeContext)
99+
override fun resolve() = neededSelection.transfer(MainHandContainer)
106100

107101
override fun ShapeBuilder.buildRenderer() {
108102
val center = pos.toCenterPos()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface InventoryConfig : ISettingGroup {
3434
val providerPriority: Priority
3535
val storePriority: Priority
3636

37+
val immediateAccessOnly: Boolean
3738
val accessShulkerBoxes: Boolean
3839
val accessEnderChest: Boolean
3940
val accessChests: Boolean

src/main/kotlin/com/lambda/interaction/material/container/ContainerManager.kt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.interaction.material.container
1919

2020
import com.lambda.context.Automated
21+
import com.lambda.context.SafeContext
2122
import com.lambda.core.Loadable
2223
import com.lambda.event.events.InventoryEvent
2324
import com.lambda.event.events.PlayerEvent
@@ -39,9 +40,8 @@ import net.minecraft.screen.ScreenHandlerType
3940

4041
// ToDo: Make this a Configurable to save container caches. Should use a cached region based storage system.
4142
object ContainerManager : Loadable {
42-
private val container: List<MaterialContainer>
43-
// ToDo: Filter containers based on a filter setting TaskFlowModule.inventory.accessEnderChest etc
44-
get() = compileContainers.filter { it !is EnderChestContainer } + runtimeContainers
43+
private val containers: List<MaterialContainer>
44+
get() = compileContainers + runtimeContainers
4545

4646
private val compileContainers = getInstances<MaterialContainer>()
4747
private val runtimeContainers = mutableSetOf<MaterialContainer>()
@@ -74,7 +74,7 @@ object ContainerManager : Loadable {
7474
val stacks = handler.containerStacks
7575

7676
this@ContainerManager.info("Updating ChestContainer")
77-
container
77+
containers
7878
.filterIsInstance<ChestContainer>()
7979
.find {
8080
it.blockPos == block.pos
@@ -85,44 +85,46 @@ object ContainerManager : Loadable {
8585
}
8686
}
8787

88-
fun container() = container.flatMap { setOf(it) + it.shulkerContainer }.sorted()
88+
fun containers() = containers.flatMap { setOf(it) + it.shulkerContainer }.sorted()
8989

90-
context(automated: Automated)
90+
context(automated: Automated, _: SafeContext)
9191
fun StackSelection.transfer(destination: MaterialContainer) =
9292
findContainerWithMaterial()?.transfer(this, destination)
9393

9494
fun findContainer(
9595
block: (MaterialContainer) -> Boolean,
96-
): MaterialContainer? = container().find(block)
96+
): MaterialContainer? = containers().find(block)
9797

98-
context(automated: Automated)
98+
context(_: Automated, _: SafeContext)
9999
fun StackSelection.findContainerWithMaterial(): MaterialContainer? =
100-
containerWithMaterial().firstOrNull()
100+
findContainersWithMaterial().firstOrNull()
101101

102-
context(automated: Automated)
102+
context(_: Automated, _: SafeContext)
103103
fun findContainerWithSpace(selection: StackSelection): MaterialContainer? =
104-
containerWithSpace(selection).firstOrNull()
104+
findContainersWithSpace(selection).firstOrNull()
105105

106-
context(automated: Automated)
107-
fun StackSelection.containerWithMaterial(
106+
context(automated: Automated, safeContext: SafeContext)
107+
fun StackSelection.findContainersWithMaterial(
108108
containerSelection: ContainerSelection = automated.inventoryConfig.containerSelection,
109109
): List<MaterialContainer> =
110-
container()
110+
containers()
111+
.filter { !automated.inventoryConfig.immediateAccessOnly || it.isImmediatelyAccessible() }
111112
.filter { it.materialAvailable(this) >= count }
112113
.filter { containerSelection.matches(it) }
113114
.sortedWith(automated.inventoryConfig.providerPriority.materialComparator(this))
114115

115-
context(automated: Automated)
116-
fun containerWithSpace(
116+
context(automated: Automated, safeContext: SafeContext)
117+
fun findContainersWithSpace(
117118
selection: StackSelection,
118119
): List<MaterialContainer> =
119-
container()
120+
containers()
121+
.filter { !automated.inventoryConfig.immediateAccessOnly || it.isImmediatelyAccessible() }
120122
.filter { it.spaceAvailable(selection) >= selection.count }
121123
.filter { automated.inventoryConfig.containerSelection.matches(it) }
122124
.sortedWith(automated.inventoryConfig.providerPriority.spaceComparator(selection))
123125

124126
context(automated: Automated)
125-
fun findDisposable() = container().find { container ->
127+
fun findDisposable() = containers().find { container ->
126128
automated.inventoryConfig.disposables.any { container.materialAvailable(it.asItem().select()) > 0 }
127129
}
128130

src/main/kotlin/com/lambda/interaction/material/container/MaterialContainer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ abstract class MaterialContainer(
138138
open fun spaceAvailable(selection: StackSelection) =
139139
matchingStacks(selection).spaceLeft + stacks.empty * selection.stackSize
140140

141+
context(safeContext: SafeContext)
142+
abstract fun isImmediatelyAccessible(): Boolean
143+
141144
context(automated: Automated)
142145
fun transfer(selection: StackSelection, destination: MaterialContainer): TransferResult {
143146
val amount = materialAvailable(selection)

0 commit comments

Comments
 (0)