Terminal GUI: add read only fake slot

This commit is contained in:
Shadowfacts 2019-10-29 20:59:46 -04:00
parent de81412630
commit 68e612c63c
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 74 additions and 0 deletions

View File

@ -31,6 +31,7 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), Invento
private var observers = 0
val cachedNetItems = ItemStackCollections.intMap()
var cachedSortedNetItems = listOf<ItemStack>()
var counter = 0
init {
@ -130,6 +131,11 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), Invento
val netAmount = entryTag.getInt("NetAmount")
cachedNetItems[stack] = netAmount
}
cachedSortedNetItems = cachedNetItems.object2IntEntrySet().sortedByDescending { it.intValue }.map {
val stack = it.key.copy()
stack.count = it.intValue
stack
}
}
}

View File

@ -17,6 +17,13 @@ class TerminalContainer(syncId: Int, playerInv: PlayerInventory, val terminal: T
}
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) {

View File

@ -0,0 +1,61 @@
package net.shadowfacts.phycon.network.block.terminal
import net.minecraft.container.Slot
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
/**
* @author shadowfacts
*/
class TerminalFakeSlot(val terminal: TerminalBlockEntity, slot: Int, x: Int, y: Int): Slot(FakeInventory(terminal, slot), slot, x, y) {
override fun canInsert(stack: ItemStack): Boolean {
return false
}
override fun setStack(stack: ItemStack) {
}
override fun canTakeItems(player: PlayerEntity): Boolean {
return false
}
}
class FakeInventory(val terminal: TerminalBlockEntity, val slot: Int): Inventory {
override fun getInvStack(_slot: Int): ItemStack {
if (slot >= terminal.cachedSortedNetItems.size) return ItemStack.EMPTY
return terminal.cachedSortedNetItems[slot]
}
override fun markDirty() {
}
override fun clear() {
}
override fun setInvStack(p0: Int, p1: ItemStack?) {
}
override fun removeInvStack(p0: Int): ItemStack {
return ItemStack.EMPTY
}
override fun canPlayerUseInv(p0: PlayerEntity?): Boolean {
return false
}
override fun getInvSize(): Int {
return 1
}
override fun takeInvStack(p0: Int, p1: Int): ItemStack {
return ItemStack.EMPTY
}
override fun isInvEmpty(): Boolean {
return false
}
}