diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ExoSuitInventoryMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ExoSuitInventoryMenu.kt index 5e6999657..131e52a6f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ExoSuitInventoryMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ExoSuitInventoryMenu.kt @@ -120,20 +120,26 @@ class ExoSuitInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen return ItemStack.EMPTY } else if (playerCombinedInventorySlots.any { it.index == slotIndex }) { - val item = slots[slotIndex].item - val copy = item.copy() - moveItemStackTo(item, playerHotbarSlots) - return copy + val copy = slots[slotIndex].item.copy() + + if (moveItemStackTo(slots[slotIndex], playerHotbarSlots)) + return copy + else + return ItemStack.EMPTY } else if (playerHotbarSlots.any { it.index == slotIndex }) { - val item = slots[slotIndex].item - val copy = item.copy() - moveItemStackTo(item, playerCombinedInventorySlots) - return copy + val copy = slots[slotIndex].item.copy() + + if (moveItemStackTo(slots[slotIndex], playerCombinedInventorySlots)) + return copy + else + return ItemStack.EMPTY } else if (craftingSlots.any { it.index == slotIndex }) { - val item = slots[slotIndex].item - val copy = item.copy() - moveItemStackTo(item, playerInventorySlots) - return copy + val copy = slots[slotIndex].item.copy() + + if (moveItemStackTo(slots[slotIndex], playerInventorySlots)) + return copy + else + return ItemStack.EMPTY } return ItemStack.EMPTY diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryMenu.kt index d9135285f..5eebfaa52 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryMenu.kt @@ -342,6 +342,26 @@ abstract class MatteryMenu @JvmOverloads protected constructor( return true } + fun moveItemStackTo( + source: Slot, + slots: Collection + ): Boolean { + val remainder = moveItemStackToSlots(source.item, slots) + + if (remainder.count == source.item.count) { + return false + } + + if (remainder.isEmpty) { + source.set(ItemStack.EMPTY) + } else { + source.item.count = remainder.count + source.setChanged() + } + + return true + } + fun moveItemStackToSlots(item: ItemStack, slots: Collection, simulate: Boolean = false): ItemStack { val copy = item.copy()