More exosuit quickmove fixes

This commit is contained in:
DBotThePony 2022-09-06 22:12:15 +07:00
parent d47fc7af41
commit 5f649d0d7e
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 38 additions and 12 deletions

View File

@ -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)
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)
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)
val copy = slots[slotIndex].item.copy()
if (moveItemStackTo(slots[slotIndex], playerInventorySlots))
return copy
else
return ItemStack.EMPTY
}
return ItemStack.EMPTY

View File

@ -342,6 +342,26 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
return true
}
fun moveItemStackTo(
source: Slot,
slots: Collection<Slot>
): 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<Slot>, simulate: Boolean = false): ItemStack {
val copy = item.copy()