???
This commit is contained in:
parent
69e4747363
commit
03dfef00c4
@ -20,6 +20,7 @@ import ru.dbotthepony.mc.otm.graph.GraphNodeList
|
|||||||
import ru.dbotthepony.mc.otm.onceServer
|
import ru.dbotthepony.mc.otm.onceServer
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
import kotlin.ConcurrentModificationException
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.HashSet
|
import kotlin.collections.HashSet
|
||||||
import kotlin.collections.LinkedHashSet
|
import kotlin.collections.LinkedHashSet
|
||||||
@ -84,6 +85,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
ContainsStatus.ABOUT_TO_BE_REMOVED, ContainsStatus.ABOUT_TO_BE_ADDED -> { } // do nothing
|
ContainsStatus.ABOUT_TO_BE_REMOVED, ContainsStatus.ABOUT_TO_BE_ADDED -> { } // do nothing
|
||||||
ContainsStatus.DOES_NOT_BELONG -> throw IllegalArgumentException("$node does not belong to $this")
|
ContainsStatus.DOES_NOT_BELONG -> throw IllegalArgumentException("$node does not belong to $this")
|
||||||
ContainsStatus.CONTAINS -> {
|
ContainsStatus.CONTAINS -> {
|
||||||
|
if (isIteratingNodes)
|
||||||
|
throw ConcurrentModificationException("Bug trap: currently iterating energy receivers!")
|
||||||
|
|
||||||
for (dir in RelativeSide.entries) {
|
for (dir in RelativeSide.entries) {
|
||||||
val pair = node to dir
|
val pair = node to dir
|
||||||
|
|
||||||
@ -590,6 +594,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onNodeRemoved(node: EnergyCableBlockEntity.Node) {
|
override fun onNodeRemoved(node: EnergyCableBlockEntity.Node) {
|
||||||
|
if (isIteratingNodes)
|
||||||
|
throw ConcurrentModificationException("Bug trap: currently iterating energy receivers!")
|
||||||
|
|
||||||
for (dir in RelativeSide.entries) {
|
for (dir in RelativeSide.entries) {
|
||||||
val pair = node to dir
|
val pair = node to dir
|
||||||
|
|
||||||
@ -618,6 +625,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onNodeAdded(node: EnergyCableBlockEntity.Node) {
|
override fun onNodeAdded(node: EnergyCableBlockEntity.Node) {
|
||||||
|
if (isIteratingNodes)
|
||||||
|
throw ConcurrentModificationException("Bug trap: currently iterating energy receivers!")
|
||||||
|
|
||||||
for (dir in RelativeSide.entries) {
|
for (dir in RelativeSide.entries) {
|
||||||
val pair = node to dir
|
val pair = node to dir
|
||||||
check(livelyNodes.add(pair))
|
check(livelyNodes.add(pair))
|
||||||
@ -627,6 +637,8 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
notifyThroughputsChanged()
|
notifyThroughputsChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var isIteratingNodes = false
|
||||||
|
|
||||||
fun receiveEnergy(howMuch: Decimal, simulate: Boolean, fromNode: EnergyCableBlockEntity.Node, fromSide: RelativeSide): Decimal {
|
fun receiveEnergy(howMuch: Decimal, simulate: Boolean, fromNode: EnergyCableBlockEntity.Node, fromSide: RelativeSide): Decimal {
|
||||||
livelyNodesList.shuffle(fromNode.blockEntity.level!!.otmRandom)
|
livelyNodesList.shuffle(fromNode.blockEntity.level!!.otmRandom)
|
||||||
|
|
||||||
@ -635,6 +647,8 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
var residue = howMuch.coerceAtMost(fromNode.energyThroughput)
|
var residue = howMuch.coerceAtMost(fromNode.energyThroughput)
|
||||||
val snapshot = Reference2ObjectOpenHashMap<Segment, Decimal>()
|
val snapshot = Reference2ObjectOpenHashMap<Segment, Decimal>()
|
||||||
|
|
||||||
|
isIteratingNodes = true
|
||||||
|
|
||||||
for (pair in itr) {
|
for (pair in itr) {
|
||||||
// recursion prevention
|
// recursion prevention
|
||||||
if (!fromNode.currentlyTransferringTo.add(pair))
|
if (!fromNode.currentlyTransferringTo.add(pair))
|
||||||
@ -737,6 +751,8 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isIteratingNodes = false
|
||||||
|
|
||||||
return received
|
return received
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user