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) }