Simplify quickMoveStack logic in MatteryMenu

This commit is contained in:
DBotThePony 2022-10-26 18:52:54 +07:00
parent 62b16ac29d
commit 3c1e74015e
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -268,53 +268,27 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
// This method receive Player interactor and slot_index where Shift + Right click occurred
// It shall return item stack that got moved
override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack {
if (storageSlots.isEmpty()) {
if (storageSlots.isEmpty() || !slots[slotIndex].hasItem() || !slots[slotIndex].mayPickup(ply)) {
return ItemStack.EMPTY
}
var moveToPlayer: Boolean? = null
if (storageSlots.any { it.index == slotIndex }) {
moveToPlayer = true
val copy = slots[slotIndex].item.copy()
if (moveItemStackTo(slots[slotIndex], _playerInventorySlots))
return copy
else
return ItemStack.EMPTY
} else if (_playerInventorySlots.any { it.index == slotIndex }) {
val copy = slots[slotIndex].item.copy()
if (moveItemStackTo(slots[slotIndex], storageSlots))
return copy
else
return ItemStack.EMPTY
}
if (moveToPlayer == null && _playerInventorySlots.any { it.index == slotIndex }) {
moveToPlayer = false
}
if (moveToPlayer == null) {
return ItemStack.EMPTY
}
var moved = ItemStack.EMPTY
val initialSlot = slots[slotIndex]
if (initialSlot.hasItem()) {
if (!initialSlot.mayPickup(ply)) {
return moved
}
val initialItem = initialSlot.item
moved = initialItem.copy()
if (moveToPlayer) {
if (!moveItemStackTo(initialItem, _playerInventorySlots)) {
return ItemStack.EMPTY
}
} else {
if (!moveItemStackTo(initialItem, storageSlots)) {
return ItemStack.EMPTY
}
}
if (initialItem.isEmpty) {
initialSlot.set(ItemStack.EMPTY)
} else {
initialSlot.setChanged()
}
}
return moved
return ItemStack.EMPTY
}
fun quickMoveToInventory(stack: ItemStack, simulate: Boolean): ItemStack {