Try to prevent recursive energy transfer on cables
This commit is contained in:
parent
3e5f47c9a3
commit
69e4747363
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.cable
|
package ru.dbotthepony.mc.otm.block.entity.cable
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArraySet
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
import net.minecraft.core.Direction
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
@ -114,6 +115,8 @@ abstract class EnergyCableBlockEntity(type: BlockEntityType<*>, blockPos: BlockP
|
|||||||
|
|
||||||
val sides get() = energySides
|
val sides get() = energySides
|
||||||
|
|
||||||
|
val currentlyTransferringTo = ObjectArraySet<Pair<Node, RelativeSide>>()
|
||||||
|
|
||||||
override fun onNeighbour(link: Link) {
|
override fun onNeighbour(link: Link) {
|
||||||
if (link is DirectionLink) {
|
if (link is DirectionLink) {
|
||||||
updateBlockState(link.direction, true)
|
updateBlockState(link.direction, true)
|
||||||
|
@ -19,6 +19,7 @@ import ru.dbotthepony.mc.otm.core.shuffle
|
|||||||
import ru.dbotthepony.mc.otm.graph.GraphNodeList
|
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 kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.HashSet
|
import kotlin.collections.HashSet
|
||||||
import kotlin.collections.LinkedHashSet
|
import kotlin.collections.LinkedHashSet
|
||||||
@ -635,6 +636,11 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
val snapshot = Reference2ObjectOpenHashMap<Segment, Decimal>()
|
val snapshot = Reference2ObjectOpenHashMap<Segment, Decimal>()
|
||||||
|
|
||||||
for (pair in itr) {
|
for (pair in itr) {
|
||||||
|
// recursion prevention
|
||||||
|
if (!fromNode.currentlyTransferringTo.add(pair))
|
||||||
|
continue
|
||||||
|
|
||||||
|
try {
|
||||||
val (node, relSide) = pair
|
val (node, relSide) = pair
|
||||||
val side = node.sides[relSide]!!
|
val side = node.sides[relSide]!!
|
||||||
|
|
||||||
@ -726,6 +732,9 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
|||||||
paths.forEach { it.shortCircuit = true }
|
paths.forEach { it.shortCircuit = true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
fromNode.currentlyTransferringTo.remove(pair)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return received
|
return received
|
||||||
|
Loading…
Reference in New Issue
Block a user