← 输入框|github.com|刷新
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
af61151
fix: keep tools in the hotbar when making room
blocksimus Oct 22, 2026
b63840e
fix: open, empty and put back shulker boxes
blocksimus Oct 22, 2026
7daa215
fix: walk to drops again after Baritone stops
blocksimus Oct 22, 2026
f6547bb
fix: open and place the right shulker box
blocksimus Oct 23, 2026
1dac2e4
fix: keep a hotbar slot until its stage comes back
blocksimus Oct 23, 2026
b3b9dee
style: put task chain steps on closing braces
blocksimus Oct 23, 2026
a57615f
fix: pick the right shulker box to open
blocksimus Oct 23, 2026
311d6a7
fix: put shulker boxes back by slot identity
blocksimus Oct 23, 2026
d5103f7
refactor: derive slot identity from container index
blocksimus Oct 24, 2026
134c2a5
replace isPreferredOver with a simple index comparison, inline contai…
beanbag44 Oct 25, 2026
a985400
fix StackSelection::emptySpace
beanbag44 Oct 25, 2026
5588477
coerce slot max count at most 64 and use the max item count for optim…
beanbag44 Oct 26, 2026
a1d2acc
add back removed SafeContext extension in InventoryManager so another…
beanbag44 Oct 26, 2026
a078478
fix: container opening and slot matching
blocksimus Oct 26, 2026
e681598
Merge remote-tracking branch 'upstream/1.21.11' into stack-fixes
blocksimus Oct 29, 2026
5ea8f66
fix: scan for nested boxes in one place
blocksimus Oct 29, 2026
9a2f2c7
refactor: let the offhand skip its own scan
blocksimus Oct 29, 2026
6b29394
fill slot whitelists and blacklists
beanbag44 Oct 30, 2026
6700385
fix: only scan stacks numbered like their slots
blocksimus Oct 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/kotlin/com/lambda/Lambda.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.lambda

import com.lambda.Lambda.mapper
import com.lambda.config.Deserializer
import com.lambda.config.FallbackDeserializer
import com.lambda.config.FallbackSerializer
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/lambda/config/ConfigCategory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.lambda.config.migration.ConfigMigrationHandler
import com.lambda.core.Loadable
import com.lambda.event.events.ClientEvent
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
import com.lambda.interaction.handler.handlers.BaritoneHandler.primary
import com.lambda.threading.runIO
import com.lambda.util.CommunicationUtils.info
import com.lambda.util.CommunicationUtils.logError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.lambda.config.categories

import com.lambda.config.ConfigCategory
import com.lambda.config.categories.ModuleCategory.name
import com.lambda.util.FolderRegistry
import java.io.File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object EnderChestContainerDeserializer : Deserializer<EnderChestContainer>(Ender
} else decodedStacks

EnderChestContainer.update(stacks)
EnderChestContainer.scanStacksForNestedContainers()
EnderChestContainer.scanContainerContents()
return EnderChestContainer
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object PlacedContainerDeserializer : FallbackDeserializer<PlacedContainer>(Place
else -> return null
}

container.scanStacksForNestedContainers()
container.scanContainerContents()
return container
}
}
5 changes: 0 additions & 5 deletions src/main/kotlin/com/lambda/event/EventFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
package com.lambda.event

import com.lambda.context.SafeContext
import com.lambda.event.EventFlow.concurrentFlow
import com.lambda.event.EventFlow.concurrentListeners
import com.lambda.event.EventFlow.lambdaScope
import com.lambda.event.EventFlow.post
import com.lambda.event.EventFlow.syncListeners
import com.lambda.event.callback.ICancellable
import com.lambda.event.listener.Listener
import com.lambda.threading.runConcurrent
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/com/lambda/event/listener/UnsafeListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import com.lambda.context.SafeContext
import com.lambda.event.Event
import com.lambda.event.EventFlow
import com.lambda.event.Muteable
import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.event.listener.SafeListener.Companion.listenConcurrently
import com.lambda.event.listener.SafeListener.Companion.listenOnce
import com.lambda.threading.runConcurrent
import com.lambda.util.Pointer
import com.lambda.util.collections.updatable
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
package com.lambda.gui.dsl

import com.lambda.gui.components.ClickGuiLayout
import com.lambda.gui.dsl.ImGuiBuilder.onItemClick
import com.lambda.gui.dsl.ImGuiBuilder.onItemHover
import com.lambda.gui.dsl.ImGuiBuilder.openPopup
import com.lambda.gui.dsl.ImGuiBuilder.text
import com.lambda.imgui.ImDrawList
import com.lambda.imgui.ImFont
import com.lambda.imgui.ImGui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.lambda.interaction.container.selection.StackSelection
import com.lambda.interaction.container.selection.select
import com.lambda.interaction.handler.handlers.BaritoneHandler
import com.lambda.task.tasks.transfer
import net.minecraft.client.data.TextureMap.side
import net.minecraft.item.ItemStack
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ class InteractSim internal constructor(simInfo: InteractSimInfo)
countEmptyAsOne()
alwaysWholeStacks()
item?.let { isItem(it) }
(targetState as? TargetState.Stack)?.let { target ->
Comment thread
beanbag44 marked this conversation as resolved.
Resolved
sortedWith { compareByDescending { it.stack === target.itemStack } }
}
sortedWith { compareByDescending { it.slot?.index == player.inventory.selectedSlot } }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import net.minecraft.state.property.Property
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction

//ToDo: Rethink this design
sealed class TargetState : StateMatcher {
data object Empty : TargetState() {
override fun toString() = "Empty"
Expand Down
23 changes: 14 additions & 9 deletions src/main/kotlin/com/lambda/interaction/container/Container.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ abstract class Container(

abstract val slots: List<Slot>
abstract var stacks: List<ItemStack>
open val stacksMatchSlots get() = this is ExternalContainer
val storedContainers = mutableMapOf<Int, NestedContainer>()

open val dimension = Dimension.Unknown
Expand All @@ -84,6 +85,8 @@ abstract class Container(

open val isAccessed get() = true

open fun slotIdentity(index: Int): SlotIdentity? = null

context(_: SafeContext)
fun descriptionAndStock(selection: StackSelection) =
buildText {
Expand Down Expand Up @@ -112,8 +115,12 @@ abstract class Container(
this.stacks = slots
}

fun scanStacksForNestedContainers() {
stacks.forEachIndexed { index, stack ->
fun scanContainerContents() {
val indexed =
slots.takeUnless { it.isEmpty() }?.map { it.index to it.stack }
?: stacks.takeIf { stacksMatchSlots }?.mapIndexed { index, stack -> index to stack }
?: return
indexed.forEach { (index, stack) ->
if (stack.item in SHULKER_BOXES) {
storedContainers[index] =
ShulkerBoxContainer(
Expand All @@ -122,7 +129,7 @@ abstract class Container(
stack.shulkerBoxStacks,
this,
index
).also { it.scanStacksForNestedContainers() }
).also { it.scanContainerContents() }
} else storedContainers.remove(index)
}
}
Expand All @@ -134,16 +141,14 @@ abstract class Container(
open fun count(selection: StackSelection) =
slots
.takeUnless { it.isEmpty() }
?.let {
selection.filter(it, false).count(selection.countEmptyAsOne)
} ?: selection.filter(stacks, false).count(selection.countEmptyAsOne)
?.let { selection.filter(it, false).count(selection.countEmptyAsOne) }
?: selection.filter(stacks, false).count(selection.countEmptyAsOne)

open fun spaceLeft(selection: StackSelection) =
slots
.takeUnless { it.isEmpty() }
?.let {
selection.filter(it, false).spaceLeft + selection.emptySpace(it)
} ?: (selection.filter(stacks, false).spaceLeft + stacks.emptySpace)
?.let { selection.filter(it, false).spaceLeft + selection.emptySpace(it) }
?: (selection.filter(stacks, false).spaceLeft + stacks.emptySpace)

open fun findSlots(selection: StackSelection) = selection.filter(slots)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ abstract class NestedContainer(type: ContainerType) : Container(type), ExternalC
abstract val containedIn: Container
abstract val index: Int

val slotIdentity get() = containedIn.slotIdentity(index)

override val dimension get() = containedIn.dimension

context(_: Automated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import com.lambda.task.Task.Ta5kBuilder
import com.lambda.task.tasks.wrappers.actionTask

interface OpenedContainerContext {
val container: Container? get() = null

@Ta5kBuilder
context(automated: Automated)
fun close(): Task<*>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ abstract class PlacedContainer(
) : Container(type), ExternalContainer {
abstract val pos: BlockPos
abstract val stash: StashContainer?
open val positions: Set<BlockPos> = setOf(pos)
open val positions: Set<BlockPos> get() = setOf(pos)

override fun slotIdentity(index: Int) = SlotIdentity.Placed(positions, index)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.lambda.interaction.container

import com.lambda.Lambda.mc
import com.lambda.context.SafeContext
import com.lambda.interaction.handler.handlers.ContainerHandler
import net.minecraft.block.entity.EnderChestBlockEntity
Expand All @@ -31,9 +32,8 @@ sealed interface SlotIdentity {
data class Placed(val positions: Set<BlockPos>, val index: Int) : SlotIdentity
data class Ender(val index: Int) : SlotIdentity

context(safeContext: SafeContext)
fun resolve(): Slot? {
val handler = safeContext.player.currentScreenHandler
val handler = mc.player?.currentScreenHandler ?: return null
val (key, ender) = currentContainerAnchor()
return resolveIn(handler.slots, key, ender)
}
Expand Down Expand Up @@ -62,6 +62,9 @@ sealed interface SlotIdentity {
if (live.isEmpty || stack.isEmpty) return false
return live.item == stack.item && live.name.string == stack.name.string
}

context(safeContext: SafeContext)
fun isEmpty() = resolve()?.stack?.isEmpty == true
}

fun Slot.identity(): SlotIdentity? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.lambda.interaction.container.containers
import com.lambda.Lambda.mc
import com.lambda.interaction.container.Container
import com.lambda.interaction.container.ContainerType
import com.lambda.interaction.container.SlotIdentity
import com.lambda.util.player.SlotUtils.armorSlots
import com.lambda.util.player.SlotUtils.armorStacks
import com.lambda.util.text.buildText
Expand All @@ -37,4 +38,6 @@ object ArmorContainer : Container(ContainerType.Armor) {
override val description = buildText { literal("Armor") }

override val isAccessed get() = mc.player?.currentScreenHandler?.syncId == 0

override fun slotIdentity(index: Int) = SlotIdentity.Player(index)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.lambda.Lambda.mc
import com.lambda.context.SafeContext
import com.lambda.interaction.container.Container
import com.lambda.interaction.container.ContainerType
import com.lambda.interaction.container.SlotIdentity
import com.lambda.interaction.manager.managers.inventory.InvRequestBuilder
import com.lambda.util.player.SlotUtils.hotbarSlots
import com.lambda.util.player.SlotUtils.hotbarStacks
Expand All @@ -39,6 +40,8 @@ object HotbarContainer : Container(ContainerType.Hotbar) {

override val description = buildText { literal("Hotbar") }

override fun slotIdentity(index: Int) = SlotIdentity.Player(index)

context(safeContext: SafeContext)
override fun InvRequestBuilder.swap(fromHere: Slot, toSlot: Slot) {
swapWithHotbar(toSlot.id, safeContext.player.hotbarSlots.indexOf(fromHere))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.lambda.interaction.container.containers
import com.lambda.Lambda.mc
import com.lambda.interaction.container.Container
import com.lambda.interaction.container.ContainerType
import com.lambda.interaction.container.SlotIdentity
import com.lambda.util.player.SlotUtils.inventorySlots
import com.lambda.util.player.SlotUtils.inventoryStacks
import com.lambda.util.text.buildText
Expand All @@ -35,4 +36,6 @@ object InventoryContainer : Container(ContainerType.Inventory) {
set(_) {}

override val description = buildText { literal("Inventory") }

override fun slotIdentity(index: Int) = SlotIdentity.Player(index)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.lambda.Lambda.mc
import com.lambda.context.SafeContext
import com.lambda.interaction.container.Container
import com.lambda.interaction.container.ContainerType
import com.lambda.interaction.container.SlotIdentity
import com.lambda.interaction.manager.managers.inventory.InvRequestBuilder
import com.lambda.util.player.SlotUtils.offHandSlots
import com.lambda.util.text.buildText
Expand All @@ -39,6 +40,8 @@ object OffhandContainer : Container(ContainerType.OffHand) {

override val description = buildText { literal("OffHand") }

override fun slotIdentity(index: Int) = SlotIdentity.Player(index)

context(safeContext: SafeContext)
override fun InvRequestBuilder.swap(fromHere: Slot, toSlot: Slot) {
swapWithHotbar(toSlot.id, 40)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ data class ChestContainer(
automated: Automated
) : OpenContainerTask<OpenedContainerContext>(description), Automated by automated {
override fun SafeContext.onStart() {
openContainer(pos)
openContainer<ChestContainer>(pos)
.onSuccess { success(BasicOpenedContainerContext(::isAccessed)) }
.start()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ data class DoubleChestContainer(
val rightDist = rightPos distSq player.pos
val closestPos = if (leftDist <= rightDist) leftPos else rightPos
val farthestPos = if (leftDist > rightDist) leftPos else rightPos
openContainer(closestPos)
.withRecovery { openContainer(farthestPos) }
openContainer<DoubleChestContainer>(closestPos)
.withRecovery { openContainer<DoubleChestContainer>(farthestPos) }
.onSuccess { success(BasicOpenedContainerContext(::isAccessed)) }
.start()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.lambda.interaction.container.ContainerType
import com.lambda.interaction.container.ExternalContainer
import com.lambda.interaction.container.OpenContainerTask
import com.lambda.interaction.container.OpenedContainerContext
import com.lambda.interaction.container.SlotIdentity
import com.lambda.interaction.container.containers.HotbarContainer
import com.lambda.interaction.container.selection.select
import com.lambda.interaction.handler.handlers.ContainerHandler.findSlot
Expand Down Expand Up @@ -67,6 +68,8 @@ object EnderChestContainer : Container(ContainerType.EnderChest), ExternalContai
mc.player?.currentScreenHandler?.typeSafe == ScreenHandlerType.GENERIC_9X3
} ?: false

override fun slotIdentity(index: Int) = SlotIdentity.Ender(index)

@Ta5kBuilder
context(automated: Automated)
override fun access() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PlacedShulkerBoxContainer(
automated: Automated
) : OpenContainerTask<BasicOpenedContainerContext>(description), Automated by automated {
override fun SafeContext.onStart() {
openContainer(pos)
openContainer<PlacedShulkerBoxContainer>(pos)
.onSuccess { success(BasicOpenedContainerContext(::isAccessed)) }
.start()
}
Expand Down
Loading