From 14125143dcb88a699db5f3c74499af61cec13fdd Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 30 Oct 2019 14:38:28 -0400 Subject: [PATCH] Terminal: Add right-clicking to request half a stack --- .../block/terminal/TerminalContainer.kt | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalContainer.kt b/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalContainer.kt index 43dbd69..0407235 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalContainer.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalContainer.kt @@ -8,6 +8,7 @@ import net.minecraft.entity.player.PlayerInventory import net.minecraft.item.ItemStack import net.minecraft.util.Identifier import net.shadowfacts.phycon.PhysicalConnectivity +import kotlin.math.ceil import kotlin.math.min /** @@ -57,16 +58,25 @@ class TerminalContainer(syncId: Int, playerInv: PlayerInventory, val terminal: T } override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity): ItemStack { - if (actionType == SlotActionType.QUICK_MOVE) { - if (slotId < 54) { - // the slot clicked was one of the network stacks - val slot = slotList[slotId] + if (slotId in 0 until 54) { + // the slot clicked was one of the network stacks + if (actionType == SlotActionType.QUICK_MOVE) { val stack = slotList[slotId].stack if (!stack.isEmpty && !player.world.isClient) { terminal.requestItem(stack, min(stack.count, stack.maxCount)) } - return ItemStack.EMPTY + } else if (actionType == SlotActionType.PICKUP && clickData == 1) { + if (clickData == 1) { + // right click, request half stack + val stack = slotList[slotId].stack + if (!stack.isEmpty && !player.world.isClient) { + terminal.requestItem(stack, ceil(min(stack.count, stack.maxCount) / 2f).toInt()) + } + } else { + // todo: left click, show amount dialog + } } + return ItemStack.EMPTY } return super.onSlotClick(slotId, clickData, actionType, player) }