From e4662b0f6f4b997ab7ae0de6ffe6f3e7af3a483d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 28 Mar 2021 13:48:56 -0400 Subject: [PATCH] Fix terminal appearing to change buffer mode to from_network when insertion fails --- .../block/terminal/AbstractTerminalBlockEntity.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt index 870b30e..deee792 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt @@ -109,7 +109,15 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>): DeviceBloc } override fun doHandleItemStack(packet: ItemStackPacket): ItemStack { - val remaining = internalBuffer.insert(packet.stack, TerminalBufferInventory.Mode.FROM_NETWORK) + val mode = + if (packet.bounceCount > 0) { + // if this stack bounced from an inventory, that means we previously tried to send it to the network, so retry + TerminalBufferInventory.Mode.TO_NETWORK + } else { + TerminalBufferInventory.Mode.FROM_NETWORK + } + + val remaining = internalBuffer.insert(packet.stack, mode) // this happens outside the normal update loop because by receiving the item stack packet // we "know" how much the count in the source inventory has changed