74 lines
1.9 KiB
Kotlin
74 lines
1.9 KiB
Kotlin
package net.shadowfacts.phycon.network.block.terminal
|
|
|
|
import net.minecraft.container.Container
|
|
import net.minecraft.container.Slot
|
|
import net.minecraft.container.SlotActionType
|
|
import net.minecraft.entity.player.PlayerEntity
|
|
import net.minecraft.entity.player.PlayerInventory
|
|
import net.minecraft.item.ItemStack
|
|
import net.minecraft.util.Identifier
|
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
import kotlin.math.min
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class TerminalContainer(syncId: Int, playerInv: PlayerInventory, val terminal: TerminalBlockEntity): Container(null, syncId) {
|
|
|
|
companion object {
|
|
val ID = Identifier(PhysicalConnectivity.MODID, "terminal")
|
|
}
|
|
|
|
init {
|
|
// network
|
|
for (y in 0 until 6) {
|
|
for (x in 0 until 9) {
|
|
addSlot(TerminalFakeSlot(terminal, y * 9 + x, 66 + x * 18, 18 + y * 18))
|
|
}
|
|
}
|
|
|
|
// internal buffer
|
|
for (y in 0 until 6) {
|
|
for (x in 0 until 3) {
|
|
addSlot(Slot(terminal.internalBuffer, y * 3 + x, 8 + x * 18, 18 + y * 18))
|
|
}
|
|
}
|
|
|
|
// player inv
|
|
for (y in 0 until 3) {
|
|
for (x in 0 until 9) {
|
|
addSlot(Slot(playerInv, x + y * 9 + 9, 66 + x * 18, 140 + y * 18))
|
|
}
|
|
}
|
|
// hotbar
|
|
for (x in 0 until 9) {
|
|
addSlot(Slot(playerInv, x, 66 + x * 18, 198))
|
|
}
|
|
}
|
|
|
|
override fun canUse(player: PlayerEntity): Boolean {
|
|
return true
|
|
}
|
|
|
|
override fun close(player: PlayerEntity) {
|
|
super.close(player)
|
|
|
|
terminal.removeObserver()
|
|
}
|
|
|
|
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]
|
|
val stack = slotList[slotId].stack
|
|
if (!stack.isEmpty && !player.world.isClient) {
|
|
terminal.requestItem(stack, min(stack.count, stack.maxCount))
|
|
}
|
|
return ItemStack.EMPTY
|
|
}
|
|
}
|
|
return super.onSlotClick(slotId, clickData, actionType, player)
|
|
}
|
|
}
|