Skip to content

Commit cd3dbe5

Browse files
committed
inventoryIndexOrSelected over inventoryIndex within the break manager in order to avoid getSlotWithStack causing problems
1 parent 5424da0 commit cd3dbe5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import com.lambda.threading.runSafe
5050
import com.lambda.util.BlockUtils.blockState
5151
import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
5252
import com.lambda.util.BlockUtils.instantBreakable
53-
import com.lambda.util.item.ItemStackUtils.inventoryIndex
53+
import com.lambda.util.item.ItemStackUtils.inventoryIndexOrSelected
5454
import com.lambda.util.math.distSq
5555
import com.lambda.util.world.raycast.RayCastUtils.blockResult
5656
import io.ktor.util.collections.*
@@ -169,7 +169,7 @@ class BreakChecker @SimCheckerDsl private constructor(simInfo: SimInfo)
169169
val breakContext = BreakContext(
170170
blockHit,
171171
rotationRequest,
172-
swapStack.inventoryIndex,
172+
swapStack.inventoryIndexOrSelected,
173173
stackSelection,
174174
instant,
175175
state,
@@ -228,7 +228,7 @@ class BreakChecker @SimCheckerDsl private constructor(simInfo: SimInfo)
228228
val breakContext = BreakContext(
229229
blockHit,
230230
rotationRequest,
231-
swapStack.inventoryIndex,
231+
swapStack.inventoryIndexOrSelected,
232232
stackSelection,
233233
instant,
234234
state,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ object ItemStackUtils {
8181

8282
context(safeContext: SafeContext)
8383
val ItemStack.inventoryIndex get() = safeContext.player.inventory.getSlotWithStack(this)
84+
context(safeContext: SafeContext)
85+
val ItemStack.inventoryIndexOrSelected get() = with(safeContext) {
86+
player.inventory.getSlotWithStack(this@inventoryIndexOrSelected).let {
87+
if (it == -1) player.inventory.selectedSlot else it
88+
}
89+
}
8490

8591
val List<ItemStack>.compressed: List<ItemStack>
8692
get() =

0 commit comments

Comments
 (0)