Fix extractor duplicating items

This commit is contained in:
Shadowfacts 2021-02-28 19:01:59 -05:00
parent 2084a749fb
commit f5268aef51
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 4 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import net.shadowfacts.phycon.api.util.IPAddress
import net.shadowfacts.phycon.packet.CapacityPacket
import net.shadowfacts.phycon.packet.CheckCapacityPacket
import net.shadowfacts.phycon.packet.ItemStackPacket
import kotlin.math.min
/**
* @author shadowfacts
@ -49,7 +50,9 @@ interface NetworkStackDispatcher<Insertion: NetworkStackDispatcher.PendingInsert
while (!remaining.isEmpty && sortedResults.isNotEmpty()) {
val (capacity, receivingInterface) = sortedResults.removeFirst()
if (capacity <= 0) continue
sendPacket(ItemStackPacket(remaining.copy(), ipAddress, receivingInterface.ipAddress))
val copy = remaining.copy()
copy.count = min(capacity, copy.count)
sendPacket(ItemStackPacket(copy, ipAddress, receivingInterface.ipAddress))
// todo: the destination should confirm how much was actually inserted, in case of race condition
remaining.count -= capacity
}