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)) + } + } } }