Tweak NetworkStackDispatcher behavior on incomplete insertions
This commit is contained in:
parent
c18af9794b
commit
33614e0dc6
|
@ -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
|
// as with extracting, we "know" the new amounts and so can update instantly without actually sending out packets
|
||||||
updateAndSync()
|
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) {
|
override fun onInventoryChanged(inv: Inventory) {
|
||||||
|
|
|
@ -36,7 +36,9 @@ interface NetworkStackDispatcher<Insertion: NetworkStackDispatcher.PendingInsert
|
||||||
insertion.results.add(packet.capacity to packet.stackReceiver)
|
insertion.results.add(packet.capacity to packet.stackReceiver)
|
||||||
if (insertion.isFinishable(this)) {
|
if (insertion.isFinishable(this)) {
|
||||||
val remaining = finishInsertion(insertion)
|
val remaining = finishInsertion(insertion)
|
||||||
// todo: do something with remaining
|
if (!remaining.isEmpty) {
|
||||||
|
pendingInsertions.add(createPendingInsertion(remaining))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,12 +58,13 @@ interface NetworkStackDispatcher<Insertion: NetworkStackDispatcher.PendingInsert
|
||||||
// copy the insertion stack so subclasses that override this method can still see the originally dispatched stack after the super call
|
// copy the insertion stack so subclasses that override this method can still see the originally dispatched stack after the super call
|
||||||
val remaining = insertion.stack.copy()
|
val remaining = insertion.stack.copy()
|
||||||
while (!remaining.isEmpty && sortedResults.isNotEmpty()) {
|
while (!remaining.isEmpty && sortedResults.isNotEmpty()) {
|
||||||
val (capacity, receivingInterface) = sortedResults.removeFirst()
|
val (capacity, receiver) = sortedResults.removeFirst()
|
||||||
if (capacity <= 0) continue
|
if (capacity <= 0) continue
|
||||||
val copy = remaining.copyWithCount(min(capacity, remaining.count))
|
val sentCount = min(capacity, remaining.count)
|
||||||
sendPacket(ItemStackPacket(copy, ipAddress, receivingInterface.ipAddress))
|
val copy = remaining.copyWithCount(sentCount)
|
||||||
|
sendPacket(ItemStackPacket(copy, ipAddress, receiver.ipAddress))
|
||||||
// todo: the destination should confirm how much was actually inserted, in case of race condition
|
// todo: the destination should confirm how much was actually inserted, in case of race condition
|
||||||
remaining.count -= capacity
|
remaining.count -= sentCount
|
||||||
}
|
}
|
||||||
|
|
||||||
return remaining
|
return remaining
|
||||||
|
@ -89,7 +92,11 @@ fun <Self, Insertion: NetworkStackDispatcher.PendingInsertion<Insertion>> Self.f
|
||||||
|
|
||||||
val finishable = pendingInsertions.filter { it.isFinishable(this) }
|
val finishable = pendingInsertions.filter { it.isFinishable(this) }
|
||||||
// finishInsertion removes the object from pendingInsertions
|
// finishInsertion removes the object from pendingInsertions
|
||||||
finishable.forEach(::finishInsertion)
|
for (insertion in finishable) {
|
||||||
// todo: do something with remaining?
|
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?)
|
// todo: if a timed-out insertion can't be finished, we should probably retry after some time (exponential backoff?)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue