From 33614e0dc67a613f70e98753971b0d8ee41ada36 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 12 Mar 2023 22:51:06 -0400 Subject: [PATCH] Tweak NetworkStackDispatcher behavior on incomplete insertions --- .../terminal/AbstractTerminalBlockEntity.kt | 3 ++- .../component/NetworkStackDispatcher.kt | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) 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 6a1cfcb..277efee 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/AbstractTerminalBlockEntity.kt @@ -225,7 +225,8 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP // as with extracting, we "know" the new amounts and so can update instantly without actually sending out packets updateAndSync() - return remaining + // don't start a second insertion, since remaining will be dispatched at the next beginInsertions + return ItemStack.EMPTY } override fun onInventoryChanged(inv: Inventory) { diff --git a/src/main/kotlin/net/shadowfacts/phycon/component/NetworkStackDispatcher.kt b/src/main/kotlin/net/shadowfacts/phycon/component/NetworkStackDispatcher.kt index 4cadc5f..6ea2f6c 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/component/NetworkStackDispatcher.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/component/NetworkStackDispatcher.kt @@ -36,7 +36,9 @@ interface NetworkStackDispatcher> Self.f val finishable = pendingInsertions.filter { it.isFinishable(this) } // finishInsertion removes the object from pendingInsertions - finishable.forEach(::finishInsertion) - // todo: do something with remaining? + for (insertion in finishable) { + val remaining = finishInsertion(insertion) + if (!remaining.isEmpty) { + pendingInsertions.add(createPendingInsertion(remaining)) + } + } // todo: if a timed-out insertion can't be finished, we should probably retry after some time (exponential backoff?) }