Skip to content

Commit b3c567d

Browse files
committed
improve / fix transferring from containers that require external actions like placing and opening a shulker, to then break and pick it up again afterward, etc.
1 parent b458dd0 commit b3c567d

File tree

20 files changed

+165
-80
lines changed

20 files changed

+165
-80
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object TransferCommand : LambdaCommand(
6767
isItem(stack(ctx).value().item)
6868
}
6969
AutomationConfig.Companion.DEFAULT.runSafeAutomated {
70-
findContainersWithSpace(selection).forEachIndexed { i, container ->
70+
selection.findContainersWithSpace().forEachIndexed { i, container ->
7171
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
7272
}
7373
}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class BuildSettings(
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/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/InteractSim.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
273273
}
274274

275275
private suspend fun AutomatedSafeContext.testPlaceState(context: ItemPlacementContext): BlockState? {
276-
val resultState = context.stack.blockItem.getPlacementState(context)
276+
val resultState = (context.stack.blockItem ?: return null).getPlacementState(context)
277277
?: run {
278278
handleEntityBlockage(context)
279279
return null
@@ -287,7 +287,7 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
287287

288288
private suspend fun AutomatedSafeContext.handleEntityBlockage(context: ItemPlacementContext): List<Entity> {
289289
val pos = context.blockPos
290-
val theoreticalState = context.stack.blockItem.block.getPlacementState(context)
290+
val theoreticalState = (context.stack.blockItem ?: return emptyList()).block.getPlacementState(context)
291291
?: return emptyList()
292292

293293
val collisionShape = theoreticalState.getCollisionShape(

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import net.minecraft.state.property.Property
3434
import net.minecraft.util.math.BlockPos
3535
import net.minecraft.util.math.Direction
3636

37-
sealed class TargetState() : StateMatcher {
37+
sealed class TargetState : StateMatcher {
3838
data object Empty : TargetState() {
3939
override fun toString() = "Empty"
4040

@@ -165,8 +165,7 @@ sealed class TargetState() : StateMatcher {
165165
}
166166

167167
data class Stack(val itemStack: ItemStack) : TargetState() {
168-
private val startStack: ItemStack = itemStack.copy()
169-
override fun toString() = "Stack of ${startStack.item.name.string.capitalize()}"
168+
override fun toString() = "Stack of ${itemStack.item.name.string.capitalize()}"
170169

171170
private val block = itemStack.item.block
172171

src/main/kotlin/com/lambda/interaction/managers/interacting/InteractManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ object InteractManager : Manager<InteractRequest>(
256256
) {
257257
ActionResult.PASS
258258
} else {
259-
val item = itemStack.blockItem
259+
val item = itemStack.blockItem ?: return ActionResult.FAIL
260260
place(interactContext, request, hand, hitResult, item, ItemPlacementContext(context))
261261
}
262262
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import net.minecraft.block.entity.ChestBlockEntity
3737
import net.minecraft.block.entity.EnderChestBlockEntity
3838
import net.minecraft.screen.GenericContainerScreenHandler
3939
import net.minecraft.screen.ScreenHandlerType
40+
import net.minecraft.screen.slot.Slot
4041

4142
// ToDo: Make this a Configurable to save container caches. Should use a cached region based storage system.
4243
object ContainerManager : Loadable {
@@ -111,9 +112,11 @@ object ContainerManager : Loadable {
111112
containerSelection: ContainerSelection = automatedSafeContext.inventoryConfig.containerSelection
112113
): MaterialContainer? = findContainersWithMaterial(containerSelection).firstOrNull()
113114

114-
context(_: AutomatedSafeContext)
115-
fun findContainerWithSpace(selection: StackSelection): MaterialContainer? =
116-
findContainersWithSpace(selection).firstOrNull()
115+
context(automatedSafeContext: AutomatedSafeContext)
116+
fun StackSelection.findContainerWithSpace(
117+
containerSelection: ContainerSelection = automatedSafeContext.inventoryConfig.containerSelection
118+
): MaterialContainer? =
119+
findContainersWithSpace(containerSelection).firstOrNull()
117120

118121
context(automated: Automated, safeContext: SafeContext)
119122
fun StackSelection.findContainersWithMaterial(
@@ -125,13 +128,21 @@ object ContainerManager : Loadable {
125128
.sortedWith(automated.inventoryConfig.providerPriority.materialComparator(this))
126129

127130
context(automatedSafeContext: AutomatedSafeContext)
128-
fun findContainersWithSpace(
129-
selection: StackSelection,
131+
fun StackSelection.findContainersWithSpace(
132+
containerSelection: ContainerSelection = automatedSafeContext.inventoryConfig.containerSelection
130133
): List<MaterialContainer> =
131134
containers()
132-
.filter { it.spaceAvailable(selection) >= selection.count }
133-
.filter { automatedSafeContext.inventoryConfig.containerSelection.matches(it) }
134-
.sortedWith(automatedSafeContext.inventoryConfig.providerPriority.spaceComparator(selection))
135+
.filter { containerSelection.matches(it) }
136+
.filter { it.spaceAvailable(this) >= count }
137+
.sortedWith(automatedSafeContext.inventoryConfig.providerPriority.spaceComparator(this))
138+
139+
context(automatedSafeContext: AutomatedSafeContext)
140+
fun StackSelection.findSlotsWithMaterial(
141+
containerSelection: ContainerSelection = automatedSafeContext.inventoryConfig.containerSelection
142+
): List<Slot> =
143+
findContainersWithMaterial(containerSelection)
144+
.flatMap { filterSlots(it.slots) }
145+
135146

136147
context(automatedSafeContext: AutomatedSafeContext)
137148
fun findDisposable() = containers().find { container ->

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

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

1818
package com.lambda.interaction.material.container
1919

20-
import com.lambda.context.Automated
20+
import com.lambda.context.AutomatedSafeContext
2121
import com.lambda.task.Task
22+
import com.lambda.task.TaskGenerator
2223

2324
interface ExternalContainer {
24-
context(_: Automated)
25-
fun access(): Task<*>
25+
context(_: AutomatedSafeContext)
26+
fun accessThen(exitAfter: Boolean = true, taskGenerator: TaskGenerator<Unit>): Task<*>?
2627
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ abstract class MaterialContainer(
6060
}.thenByDescending {
6161
it.stack.item in automated.inventoryConfig.disposables
6262
}.thenByDescending {
63-
it.stack.item.components.contains(DataComponentTypes.TOOL)
63+
!it.stack.item.components.contains(DataComponentTypes.TOOL)
6464
}.thenByDescending {
65-
it.stack.item.components.contains(DataComponentTypes.FOOD)
65+
!it.stack.item.components.contains(DataComponentTypes.FOOD)
6666
}.thenByDescending {
6767
it.stack.isStackable
6868
}
@@ -130,7 +130,7 @@ abstract class MaterialContainer(
130130
fun transfer(stackSelection: StackSelection, destination: MaterialContainer): Boolean =
131131
with(automatedSafeContext) {
132132
val fromSlot = getSlot(stackSelection) ?: return false
133-
val toSlot = destination.getReplaceSlot() ?: return false
133+
val toSlot = destination.getReplaceableSlot() ?: return false
134134
return inventoryRequest {
135135
if (swapMethodPriority > destination.swapMethodPriority) transfer(fromSlot, toSlot)
136136
else with(destination) { transfer(toSlot, fromSlot) }
@@ -163,7 +163,7 @@ abstract class MaterialContainer(
163163
matchingStacks(selection).spaceLeft + stacks.empty * selection.stackSize
164164

165165
context(_: AutomatedSafeContext)
166-
open fun getReplaceSlot() = slots.sortedWith(replaceSorter).firstOrNull()
166+
open fun getReplaceableSlot() = slots.sortedWith(replaceSorter).firstOrNull()
167167

168168
context(_: SafeContext)
169169
open fun getSlot(stackSelection: StackSelection): Slot? =

0 commit comments

Comments
 (0)