Skip to content

Commit 9b034a6

Browse files
committed
fix inventory id and index extension getters
1 parent 8950b53 commit 9b034a6

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ object ItemStackUtils {
8080
val List<ItemStack>.copy: List<ItemStack> get() = map { it.copy() }
8181

8282
context(safeContext: SafeContext)
83-
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-
}
83+
val ItemStack.slotId get() = safeContext.player.currentScreenHandler.slots.find { it.stack.equal(this) }?.id ?: -1
84+
context(safeContext: SafeContext)
85+
val ItemStack.inventoryIndex get() = safeContext.player.inventory.getSlotWithStack(this)
86+
context(safeContext: SafeContext)
87+
val ItemStack.inventoryIndexOrSelected get() = inventoryIndex.let { if (it == -1) safeContext.player.inventory.selectedSlot else it }
9088

9189
val List<ItemStack>.compressed: List<ItemStack>
9290
get() =

0 commit comments

Comments
 (0)