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
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package li.cil.oc.integration.appeng

import appeng.api.AEApi
import appeng.api.networking.IGrid
import appeng.api.parts.IPartHost
import appeng.api.util.{DimensionalCoord, IInterfaceViewable}
import appeng.parts.AEBasePart
import appeng.parts.misc.PartPatternRepeater
import appeng.parts.p2p.PartP2PTunnel
import appeng.parts.reporting.PartInterfaceTerminal
import li.cil.oc.api.driver
Expand Down Expand Up @@ -180,8 +182,9 @@ object DriverPartInterfaceTerminal extends driver.SidedBlock {
private def allMachines: Iterable[IInterfaceViewable] = {
val grid = getGrid
if (grid == null) return Array.empty[IInterfaceViewable]
AEApi.instance().registries().interfaceTerminal().getSupportedClasses.view
.flatMap(c => grid.getMachines(c).asScala)
val supported = AEApi.instance().registries().interfaceTerminal().getSupportedClasses
reachableGrids(grid).view
.flatMap(g => supported.view.flatMap(c => g.getMachines(c).asScala))
.map(_.getMachine.asInstanceOf[IInterfaceViewable])
.filter { m =>
m.shouldDisplay && (m match {
Expand All @@ -191,6 +194,25 @@ object DriverPartInterfaceTerminal extends driver.SidedBlock {
}
}

private def reachableGrids(start: IGrid): Iterable[IGrid] = {
val grids = mutable.LinkedHashSet[IGrid](start)
val pending = mutable.Queue[IGrid](start)
while (pending.nonEmpty) {
for (node <- pending.dequeue().getMachines(classOf[PartPatternRepeater]).asScala) {
val repeater = node.getMachine.asInstanceOf[PartPatternRepeater]
val pair = repeater.getPair
if (repeater.isProvider && node.isActive && pair != null && !pair.isProvider) {
val pairNode = pair.getGridNode
if (pairNode != null && pairNode.isActive) {
val pairGrid = pairNode.getGrid
if (grids.add(pairGrid)) pending.enqueue(pairGrid)
}
}
}
}
grids
}

private def getGrid = part.getActionableNode.getGrid
}

Expand Down