Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/main/scala/mrtjp/projectred/transportation/ChipExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import mrtjp.core.inventory.InvWrapper

import scala.collection.immutable.BitSet
import scala.collection.mutable.ListBuffer
import util.control.Breaks._

class ChipExtractor extends RoutingChip with TChipFilter with TChipOrientation {
private var remainingDelay = operationDelay
Expand Down Expand Up @@ -35,20 +36,21 @@ class ChipExtractor extends RoutingChip with TChipFilter with TChipOrientation {
stackSize != 0 &&
filt.hasItem(stackKey) != filterExclude
) {
var exclusions = BitSet.empty
var s = routeLayer.getLogisticPath(stackKey, exclusions, true)
if (s != null) {
var leftInRun = itemsToExtract
val maxRunSize = math.min(itemsToExtract, stackSize)
var leftInRun = maxRunSize

breakable {
var exclusions = BitSet.empty
var s = routeLayer.getLogisticPath(stackKey, exclusions, true)
while (s != null) {
var toExtract = math.min(leftInRun, stackSize)
toExtract = math.min(toExtract, stackKey.getMaxStackSize)
var toExtract = math.min(leftInRun, stackKey.getMaxStackSize)
toExtract = math.min(toExtract, s.itemCount)

if (toExtract <= 0) return
if (toExtract <= 0) break
Comment thread
branan marked this conversation as resolved.

val stack2 =
stackKey.makeStack(inv.extractItem(stackKey, toExtract))
if (stack2.stackSize <= 0) return
if (stack2.stackSize <= 0) break

routeLayer.queueStackToSend(
stack2,
Expand All @@ -57,12 +59,15 @@ class ChipExtractor extends RoutingChip with TChipFilter with TChipOrientation {
)

leftInRun -= stack2.stackSize
if (leftInRun <= 0) return
if (leftInRun <= 0) break
Comment thread
branan marked this conversation as resolved.

exclusions += s.responder
s = routeLayer.getLogisticPath(stackKey, exclusions, true)
}
}

// Confirm that we actually extracted something. If not, we can still try the next item type
if (leftInRun < maxRunSize) return
}
}
}
Expand Down
Loading