diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableBlockEntity.kt index 61741903d..829192b37 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableBlockEntity.kt @@ -111,11 +111,6 @@ abstract class EnergyCableBlockEntity(type: BlockEntityType<*>, blockPos: BlockP _segment = value } - fun onInvalidate() { - _segment = EnergyCableGraph.Segment(this) - updatePoweredState(false) - } - val sides get() = energySides override fun onNeighbour(link: Link) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt index 81525d3db..2e5dbd9c0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/cable/EnergyCableGraph.kt @@ -68,7 +68,7 @@ class EnergyCableGraph : GraphNodeList() val nodes = HashSet() var shortCircuit = false @@ -136,7 +136,7 @@ class EnergyCableGraph : GraphNodeList() - private var paths = ReferenceLinkedOpenHashSet() + var paths = ReferenceLinkedOpenHashSet() operator fun contains(node: EnergyCableBlockEntity.Node): Boolean { return node in nodes @@ -338,6 +338,26 @@ class EnergyCableGraph : GraphNodeList { + val result = ArrayList() + result.add(this) + + for (v in nodes) { + val segment = Segment() + v._segment = segment + segment.nodes.add(v) + segment.throughput = v.energyThroughput + segment.throughputKnown = true + segment.transferredLastTick = transferredLastTick + result.add(segment) + v.updatePoweredState(false) + } + + // mark this segment as dead + this.nodes.clear() + return result + } + private fun combineInto(segment: Segment) { nodes.forEach { it._segment = segment } segment.nodes.addAll(nodes) @@ -385,11 +405,6 @@ class EnergyCableGraph : GraphNodeList, threshold: Decimal): SegmentPath? { val seenTop = existing.any { a in it } @@ -435,7 +450,7 @@ class EnergyCableGraph : GraphNodeList