From 68e612c63cdd62004402553f438867766e2b2bd7 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 29 Oct 2019 20:59:46 -0400 Subject: [PATCH] Terminal GUI: add read only fake slot --- .../block/terminal/TerminalBlockEntity.kt | 6 ++ .../block/terminal/TerminalContainer.kt | 7 +++ .../block/terminal/TerminalFakeSlot.kt | 61 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalFakeSlot.kt diff --git a/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalBlockEntity.kt b/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalBlockEntity.kt index 4cae69e..6ea62d5 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalBlockEntity.kt @@ -31,6 +31,7 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), Invento private var observers = 0 val cachedNetItems = ItemStackCollections.intMap() + var cachedSortedNetItems = listOf() 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 + } } } 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 3fdd0c5..311059d 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 @@ -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) { diff --git a/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalFakeSlot.kt b/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalFakeSlot.kt new file mode 100644 index 0000000..17bbcc3 --- /dev/null +++ b/src/main/kotlin/net/shadowfacts/phycon/network/block/terminal/TerminalFakeSlot.kt @@ -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 + } + +}