diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/Abstract6Graph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/Abstract6Graph.kt index 5d10b8612..476a3d96c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/Abstract6Graph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/Abstract6Graph.kt @@ -1,6 +1,5 @@ package ru.dbotthepony.mc.otm.graph -import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.core.SectionPos @@ -14,14 +13,10 @@ import kotlin.collections.ArrayList import kotlin.collections.HashMap abstract class Abstract6Graph : IConditionalTickable { - @JvmField - protected val _nodes = ArrayList>() - fun size() = _nodes.size - + protected val nodes = ArrayList>() + fun size() = nodes.size private val tickable = ArrayList>() - - @JvmField - val nodes: Collection> = Collections.unmodifiableCollection(_nodes) + val nodeList: Collection> = Collections.unmodifiableCollection(nodes) /** * Allows storing arbitrary data by external code @@ -33,7 +28,7 @@ abstract class Abstract6Graph : IConditionalTickable { abstract fun onNodeAdded(node: Graph6Node) override val canTick: Boolean - get() = _nodes.size > 0 + get() = nodes.size > 0 override fun tick() { for (i in tickable.size - 1 downTo 0) { @@ -48,10 +43,9 @@ abstract class Abstract6Graph : IConditionalTickable { } fun removeNode(node: Graph6Node) { - if (!_nodes.contains(node)) + if (!nodes.remove(node)) throw IllegalStateException("Not containing node $node") - _nodes.remove(node) node.graph = null onNodeRemoved(node) @@ -61,10 +55,10 @@ abstract class Abstract6Graph : IConditionalTickable { } fun addNode(node: Graph6Node) { - if (_nodes.contains(node)) + if (nodes.contains(node)) throw IllegalStateException("Already containing node $node") - _nodes.add(node) + nodes.add(node) node.graph = this onNodeAdded(node) @@ -78,8 +72,8 @@ abstract class Abstract6Graph : IConditionalTickable { return this if (size() >= other.size()) { - for (node in other._nodes) { - _nodes.add(node) + for (node in other.nodes) { + nodes.add(node) node.graph = this onNodeAdded(node) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/MatterNetworkGraph.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/MatterNetworkGraph.kt index 072320ba4..88100391a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/MatterNetworkGraph.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/graph/matter/MatterNetworkGraph.kt @@ -74,7 +74,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun getMatterStorageLevel(): ImpreciseFraction { var level = ImpreciseFraction.ZERO - for (node in _nodes) { + for (node in nodes) { val matter = node.value.getMatterHandler() if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) { @@ -88,7 +88,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun getMatterStorageMaxLevel(): ImpreciseFraction { var level = ImpreciseFraction.ZERO - for (node in _nodes) { + for (node in nodes) { val matter = node.value.getMatterHandler() if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) { @@ -106,7 +106,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe var howMuch = howMuch var extracted = ImpreciseFraction.ZERO - for (node in _nodes) { + for (node in nodes) { val matter = node.value.getMatterHandler() if (matter != null) { @@ -129,7 +129,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe var howMuch = howMuch var received = ImpreciseFraction.ZERO - for (node in _nodes) { + for (node in nodes) { val matter = node.value.getMatterHandler() if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) { @@ -152,7 +152,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe var howMuch = howMuch var received = ImpreciseFraction.ZERO - for (node in _nodes) { + for (node in nodes) { val matter = node.value.getMatterHandler() if (matter != null && matter.direction != MatterDirection.EXTRACT) { @@ -169,7 +169,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe } private fun _insertPattern(state: PatternState, onlyUpdate: Boolean, simulate: Boolean): PatternInsertStatus { - for (node in _nodes) { + for (node in nodes) { val storage = node.value.getPatternHandler() if (storage != null) { @@ -194,7 +194,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun getTasks(): Collection { val list = ArrayList() - for (node in _nodes) { + for (node in nodes) { val tasks = node.value.getTaskHandler() if (tasks != null) { @@ -208,7 +208,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun getStoredPatterns(): Collection { val list = ArrayList() - for (node in _nodes) { + for (node in nodes) { val storage = node.value.getPatternHandler() if (storage != null) { @@ -222,7 +222,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun getPatternCount(): Long { var value = 0L - for (node in _nodes) { + for (node in nodes) { val storage = node.value.getPatternHandler() if (storage != null) { @@ -236,7 +236,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun getPatternCapacity(): Long { var value = 0L - for (node in _nodes) { + for (node in nodes) { val storage = node.value.getPatternHandler() if (storage != null) { @@ -248,7 +248,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe } fun getPattern(id: UUID): PatternState? { - for (node in _nodes) { + for (node in nodes) { val storage = node.value.getPatternHandler() if (storage != null) { @@ -268,7 +268,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun hasPattern(id: UUID) = getPattern(id) != null fun findPattern(predicate: (PatternState) -> Boolean): PatternState? { - for (node in _nodes) { + for (node in nodes) { val storage = node.value.getPatternHandler() if (storage != null) { @@ -288,7 +288,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun findPatterns(predicate: (PatternState) -> Boolean): Collection { val list = ArrayList() - for (node in _nodes) { + for (node in nodes) { val storage = node.value.getPatternHandler() if (storage != null) { @@ -306,7 +306,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe fun findPatterns(predicate: Item) = findPatterns { it.item == predicate } fun allocateTask(simulate: Boolean): MatterTaskAllocation? { - for (node in _nodes) { + for (node in nodes) { val tasks = node.value.getTaskHandler() if (tasks != null) { @@ -322,7 +322,7 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe } fun notifyTaskCompletion(task: MatterTask): Boolean { - for (node in _nodes) { + for (node in nodes) { val tasks = node.value.getTaskHandler() if (tasks != null && tasks.notifyTaskCompletion(task)) { @@ -334,37 +334,37 @@ class MatterNetworkGraph : Abstract6Graph(), IMatterGraphListe } override fun onPatternAdded(state: PatternState) { - for (node in _nodes) node.value.onPatternAdded(state) + for (node in nodes) node.value.onPatternAdded(state) for (node in listeners) node.onPatternAdded(state) } override fun onPatternRemoved(state: PatternState) { - for (node in _nodes) node.value.onPatternRemoved(state) + for (node in nodes) node.value.onPatternRemoved(state) for (node in listeners) node.onPatternRemoved(state) } override fun onPatternUpdated(new_state: PatternState, old_state: PatternState) { - for (node in _nodes) node.value.onPatternUpdated(new_state, old_state) + for (node in nodes) node.value.onPatternUpdated(new_state, old_state) for (node in listeners) node.onPatternUpdated(new_state, old_state) } override fun onMatterTaskCreated(task: MatterTask) { - for (node in _nodes) node.value.onMatterTaskCreated(task) + for (node in nodes) node.value.onMatterTaskCreated(task) for (node in listeners) node.onMatterTaskCreated(task) } override fun onMatterTaskUpdated(new_state: MatterTask, old_state: MatterTask) { - for (node in _nodes) node.value.onMatterTaskUpdated(new_state, old_state) + for (node in nodes) node.value.onMatterTaskUpdated(new_state, old_state) for (node in listeners) node.onMatterTaskUpdated(new_state, old_state) } override fun onMatterTaskFinished(state: MatterTask) { - for (node in _nodes) node.value.onMatterTaskFinished(state) + for (node in nodes) node.value.onMatterTaskFinished(state) for (node in listeners) node.onMatterTaskFinished(state) } override fun onMatterTaskRemoved(state: MatterTask) { - for (node in _nodes) node.value.onMatterTaskRemoved(state) + for (node in nodes) node.value.onMatterTaskRemoved(state) for (node in listeners) node.onMatterTaskRemoved(state) }