Fix not being able to extract more than max stack size from interface
This commit is contained in:
parent
aec32ae270
commit
03c9c2ab83
|
@ -14,6 +14,7 @@ import net.shadowfacts.phycon.network.component.NetworkStackProvider
|
||||||
import net.shadowfacts.phycon.network.component.NetworkStackReceiver
|
import net.shadowfacts.phycon.network.component.NetworkStackReceiver
|
||||||
import net.shadowfacts.phycon.network.component.handleItemStack
|
import net.shadowfacts.phycon.network.component.handleItemStack
|
||||||
import net.shadowfacts.phycon.network.packet.*
|
import net.shadowfacts.phycon.network.packet.*
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
|
@ -67,10 +68,18 @@ class InterfaceBlockEntity: DeviceBlockEntity(PhyBlockEntities.INTERFACE),
|
||||||
|
|
||||||
private fun handleExtractStack(packet: ExtractStackPacket) {
|
private fun handleExtractStack(packet: ExtractStackPacket) {
|
||||||
getInventory()?.also { inv ->
|
getInventory()?.also { inv ->
|
||||||
val extracted = inv.extract(packet.stack, packet.amount)
|
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))
|
sendPacket(ItemStackPacket(extracted, ipAddress, packet.source))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleCheckCapacity(packet: CheckCapacityPacket) {
|
private fun handleCheckCapacity(packet: CheckCapacityPacket) {
|
||||||
getInventory()?.also { inv ->
|
getInventory()?.also { inv ->
|
||||||
|
|
Loading…
Reference in New Issue