Simplify quickMoveStack logic in MatteryMenu
This commit is contained in:
parent
62b16ac29d
commit
3c1e74015e
@ -268,54 +268,28 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
|||||||
// This method receive Player interactor and slot_index where Shift + Right click occurred
|
// This method receive Player interactor and slot_index where Shift + Right click occurred
|
||||||
// It shall return item stack that got moved
|
// It shall return item stack that got moved
|
||||||
override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack {
|
override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack {
|
||||||
if (storageSlots.isEmpty()) {
|
if (storageSlots.isEmpty() || !slots[slotIndex].hasItem() || !slots[slotIndex].mayPickup(ply)) {
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
var moveToPlayer: Boolean? = null
|
|
||||||
|
|
||||||
if (storageSlots.any { it.index == slotIndex }) {
|
if (storageSlots.any { it.index == slotIndex }) {
|
||||||
moveToPlayer = true
|
val copy = slots[slotIndex].item.copy()
|
||||||
}
|
|
||||||
|
|
||||||
if (moveToPlayer == null && _playerInventorySlots.any { it.index == slotIndex }) {
|
if (moveItemStackTo(slots[slotIndex], _playerInventorySlots))
|
||||||
moveToPlayer = false
|
return copy
|
||||||
}
|
else
|
||||||
|
return ItemStack.EMPTY
|
||||||
|
} else if (_playerInventorySlots.any { it.index == slotIndex }) {
|
||||||
|
val copy = slots[slotIndex].item.copy()
|
||||||
|
|
||||||
if (moveToPlayer == null) {
|
if (moveItemStackTo(slots[slotIndex], storageSlots))
|
||||||
|
return copy
|
||||||
|
else
|
||||||
return ItemStack.EMPTY
|
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
|
return ItemStack.EMPTY
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (!moveItemStackTo(initialItem, storageSlots)) {
|
|
||||||
return ItemStack.EMPTY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (initialItem.isEmpty) {
|
|
||||||
initialSlot.set(ItemStack.EMPTY)
|
|
||||||
} else {
|
|
||||||
initialSlot.setChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return moved
|
|
||||||
}
|
|
||||||
|
|
||||||
fun quickMoveToInventory(stack: ItemStack, simulate: Boolean): ItemStack {
|
fun quickMoveToInventory(stack: ItemStack, simulate: Boolean): ItemStack {
|
||||||
if (_playerInventorySlots.isEmpty()) {
|
if (_playerInventorySlots.isEmpty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user