Don't sort cable paths when simulating transfer
This commit is contained in:
parent
7846b3f5a4
commit
4ef66dff7c
@ -8,6 +8,7 @@ import it.unimi.dsi.fastutil.objects.ReferenceArraySet
|
|||||||
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet
|
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import org.apache.logging.log4j.LogManager
|
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.UNIVERSE_TICKS
|
||||||
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
@ -76,6 +77,10 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
val availableThroughput: Decimal
|
val availableThroughput: Decimal
|
||||||
get() = segments.minOfOrNull { it.availableThroughput } ?: Decimal.ZERO
|
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 {
|
operator fun contains(node: EnergyCableBlockEntity.Node): Boolean {
|
||||||
return segments.any { node in it }
|
return segments.any { node in it }
|
||||||
}
|
}
|
||||||
@ -186,7 +191,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
hasBlockstateTimer = updateBlockstates()
|
hasBlockstateTimer = updateBlockstates()
|
||||||
lastPoweredSwitchFrequency = (lastPoweredSwitchFrequency shl 1) or (if (changed) 1 else 0)
|
lastPoweredSwitchFrequency = (lastPoweredSwitchFrequency shl 1) or (if (changed) 1 else 0)
|
||||||
|
|
||||||
if (hasBlockstateTimer) {
|
if (hasBlockstateTimer && SERVER_IS_LIVE) {
|
||||||
var i = 20
|
var i = 20
|
||||||
|
|
||||||
for (index in 0 .. 16) {
|
for (index in 0 .. 16) {
|
||||||
@ -417,7 +422,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
return null
|
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)
|
if (!a.canTraverse || !b.canTraverse)
|
||||||
return listOf()
|
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
|
return list.paths
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,7 +485,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
val it = side.neighbour.get() ?: continue
|
val it = side.neighbour.get() ?: continue
|
||||||
if (it is EnergyCableBlockEntity.CableSide) continue
|
if (it is EnergyCableBlockEntity.CableSide) continue
|
||||||
|
|
||||||
val paths = getPath(fromNode, node, residue)
|
val paths = getPath(fromNode, node, residue, !simulate)
|
||||||
hit = true
|
hit = true
|
||||||
|
|
||||||
if (paths.size == 1) {
|
if (paths.size == 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user