Terminal: Add right-clicking to request half a stack

This commit is contained in:
Shadowfacts 2019-10-30 14:38:28 -04:00
parent 37692aac7d
commit 14125143dc
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 15 additions and 5 deletions

View File

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