Skip to content

Commit f71bfc3

Browse files
committed
small item stack utils edit to account for empty slots and remove Resolvable from CantReplace place result
1 parent 745d557 commit f71bfc3

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

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

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

2020
import baritone.api.pathing.goals.GoalBlock
2121
import baritone.api.pathing.goals.GoalInverted
22-
import com.lambda.context.Automated
2322
import com.lambda.graphics.renderer.esp.ShapeBuilder
2423
import com.lambda.interaction.construction.context.PlaceContext
2524
import com.lambda.interaction.construction.result.BuildResult
@@ -28,8 +27,6 @@ import com.lambda.interaction.construction.result.Dependent
2827
import com.lambda.interaction.construction.result.Drawable
2928
import com.lambda.interaction.construction.result.Navigable
3029
import com.lambda.interaction.construction.result.Rank
31-
import com.lambda.interaction.construction.result.Resolvable
32-
import com.lambda.task.tasks.BuildTask.Companion.breakBlock
3330
import net.minecraft.block.BlockState
3431
import net.minecraft.entity.Entity
3532
import net.minecraft.item.ItemPlacementContext
@@ -142,11 +139,8 @@ sealed class PlaceResult : BuildResult() {
142139
data class CantReplace(
143140
override val pos: BlockPos,
144141
val simulated: ItemPlacementContext,
145-
) : Resolvable, PlaceResult() {
142+
) : PlaceResult() {
146143
override val rank = Rank.PlaceCantReplace
147-
148-
context(automated: Automated)
149-
override fun resolve() = automated.breakBlock(pos)
150144
}
151145

152146
/**

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class BreakSim private constructor(simInfo: ISimInfo)
148148
}
149149

150150
private fun AutomatedSafeContext.getSwapStack(): Pair<ItemStack, StackSelection>? {
151+
// Stack size 0 to account for attacking with an empty hand. Empty slots have stack size 0
151152
val stackSelection = selectStack(
152153
count = 0,
153154
sorter = compareByDescending<ItemStack> {
@@ -186,18 +187,18 @@ class BreakSim private constructor(simInfo: ISimInfo)
186187
ofAnyType(MaterialContainer.Rank.Hotbar)
187188
}
188189

189-
val swapCandidates = stackSelection
190+
val hotbarCandidates = stackSelection
190191
.containerWithMaterial(silentSwapSelection)
191192
.map { it.matchingStacks(stackSelection) }
192193
.flatten()
193-
if (swapCandidates.isEmpty()) {
194+
if (hotbarCandidates.isEmpty()) {
194195
result(GenericResult.WrongItemSelection(pos, stackSelection, player.mainHandStack))
195196
return null
196197
}
197198

198199
var bestStack = ItemStack.EMPTY
199200
var bestBreakDelta = -1f
200-
swapCandidates.forEach { stack ->
201+
hotbarCandidates.forEach { stack ->
201202
val breakDelta = state.calcItemBlockBreakingDelta(pos, stack)
202203
if (breakDelta > bestBreakDelta ||
203204
(stack == player.mainHandStack && breakDelta >= bestBreakDelta)

src/main/kotlin/com/lambda/util/item/ItemStackUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ object ItemStackUtils {
7676
val ItemStack.hasSpace get() = spaceLeft > 0
7777
val List<ItemStack>.spaceLeft get() = sumOf { it.spaceLeft }
7878
val List<ItemStack>.empty: Int get() = count { it.isEmpty }
79-
val List<ItemStack>.count: Int get() = sumOf { it.count }
79+
val List<ItemStack>.count: Int get() = if (isEmpty()) -1 else sumOf { it.count }
8080
val List<ItemStack>.copy: List<ItemStack> get() = map { it.copy() }
8181

8282
context(safeContext: SafeContext)

0 commit comments

Comments
 (0)