Don't sort cable paths when simulating transfer

This commit is contained in:
DBotThePony 2025-01-18 16:11:17 +07:00
parent 7846b3f5a4
commit 4ef66dff7c
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -8,6 +8,7 @@ import it.unimi.dsi.fastutil.objects.ReferenceArraySet
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet
import net.minecraft.core.BlockPos
import org.apache.logging.log4j.LogManager
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.core.math.Decimal
@ -76,6 +77,10 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
val availableThroughput: Decimal
get() = segments.minOfOrNull { it.availableThroughput } ?: Decimal.ZERO
fun availableThroughput(instantSnapshot: Reference2ObjectOpenHashMap<Segment, Decimal>): Decimal {
return segments.minOfOrNull { it.throughput(instantSnapshot) } ?: Decimal.ZERO
}
operator fun contains(node: EnergyCableBlockEntity.Node): Boolean {
return segments.any { node in it }
}
@ -186,7 +191,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
hasBlockstateTimer = updateBlockstates()
lastPoweredSwitchFrequency = (lastPoweredSwitchFrequency shl 1) or (if (changed) 1 else 0)
if (hasBlockstateTimer) {
if (hasBlockstateTimer && SERVER_IS_LIVE) {
var i = 20
for (index in 0 .. 16) {
@ -417,7 +422,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
return null
}
private fun getPath(a: EnergyCableBlockEntity.Node, b: EnergyCableBlockEntity.Node, energyToTransfer: Decimal): List<SegmentPath> {
private fun getPath(a: EnergyCableBlockEntity.Node, b: EnergyCableBlockEntity.Node, energyToTransfer: Decimal, sort: Boolean): List<SegmentPath> {
if (!a.canTraverse || !b.canTraverse)
return listOf()
@ -438,7 +443,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
}
}
list.paths.sortByDescending { it.availableThroughput }
if (sort)
list.paths.sortByDescending { it.availableThroughput }
return list.paths
}
@ -478,7 +485,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
val it = side.neighbour.get() ?: continue
if (it is EnergyCableBlockEntity.CableSide) continue
val paths = getPath(fromNode, node, residue)
val paths = getPath(fromNode, node, residue, !simulate)
hit = true
if (paths.size == 1) {