From 03c9c2ab830600433d311560d291595ab98365d9 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 20 Feb 2021 14:17:44 -0500 Subject: [PATCH] Fix not being able to extract more than max stack size from interface --- .../block/netinterface/InterfaceBlockEntity.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/phycon/network/block/netinterface/InterfaceBlockEntity.kt b/src/main/kotlin/net/shadowfacts/phycon/network/block/netinterface/InterfaceBlockEntity.kt index 85500f6..841324e 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/network/block/netinterface/InterfaceBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/network/block/netinterface/InterfaceBlockEntity.kt @@ -14,6 +14,7 @@ import net.shadowfacts.phycon.network.component.NetworkStackProvider import net.shadowfacts.phycon.network.component.NetworkStackReceiver import net.shadowfacts.phycon.network.component.handleItemStack import net.shadowfacts.phycon.network.packet.* +import kotlin.math.min /** * @author shadowfacts @@ -67,8 +68,16 @@ class InterfaceBlockEntity: DeviceBlockEntity(PhyBlockEntities.INTERFACE), private fun handleExtractStack(packet: ExtractStackPacket) { getInventory()?.also { inv -> - val extracted = inv.extract(packet.stack, packet.amount) - sendPacket(ItemStackPacket(extracted, ipAddress, packet.source)) + var amount = packet.amount + while (amount > 0) { + val extracted = inv.extract(packet.stack, min(amount, packet.stack.maxCount)) + if (extracted.isEmpty) { + break + } else { + amount -= extracted.count + sendPacket(ItemStackPacket(extracted, ipAddress, packet.source)) + } + } } }