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 9949039cb..1e2053a9f 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 @@ -8,6 +8,7 @@ import ru.dbotthepony.mc.otm.SERVER_IS_LIVE import ru.dbotthepony.mc.otm.UNIVERSE_TICKS import ru.dbotthepony.mc.otm.capability.receiveEnergy import ru.dbotthepony.mc.otm.config.CablesConfig +import ru.dbotthepony.mc.otm.core.addAll import ru.dbotthepony.mc.otm.core.collect.map import ru.dbotthepony.mc.otm.core.collect.reduce import ru.dbotthepony.mc.otm.core.math.Decimal @@ -186,7 +187,7 @@ class EnergyCableGraph : GraphNodeList() + val nodes = LinkedHashSet() var paths = ReferenceLinkedOpenHashSet() operator fun contains(node: EnergyCableBlockEntity.Node): Boolean { @@ -244,7 +245,7 @@ class EnergyCableGraph : GraphNodeList) { - if (nodes.isEmpty()) return + if (nodes.isEmpty() || paths.isEmpty()) return for (segment in with) { if (tryCombineWith(segment)) return @@ -581,12 +585,23 @@ class EnergyCableGraph : GraphNodeList() + + node.segment.paths.toTypedArray().forEach { pathCache.remove(it.a to it.b) + + it.segments.forEach { s -> + touchedSegments.add(s) + s.paths.remove(it) + + // this doesn't cover 100% of cases where previously split path segments + // due to "this" path get recombined, but it should be good enough + s.paths.forEach { touchedSegments.addAll(it.segments) } + } } - node.segment.paths = ReferenceLinkedOpenHashSet() - node.segment.split() + touchedSegments.addAll(node.segment.split()) + touchedSegments.forEach { it.tryCombine(touchedSegments) } } override fun onNodeAdded(node: EnergyCableBlockEntity.Node) {