Compare commits
No commits in common. "486060c8a4ecff6a25f2b9c143dd7dd2abfa0394" and "fdc9944c17c41d14f67eb671ef64d31f20ebaf84" have entirely different histories.
486060c8a4
...
fdc9944c17
@ -413,6 +413,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
}
|
||||
|
||||
private var _subCache: ChunkSubscribers? = null
|
||||
private val subscription get() = _subCache ?: subscribe()
|
||||
private var playerListUpdated = false
|
||||
|
||||
private fun unsubscribe() {
|
||||
@ -429,10 +430,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
playerListUpdated = false
|
||||
}
|
||||
|
||||
private fun subscribe() {
|
||||
if (!syncher.hasChildren)
|
||||
return
|
||||
|
||||
private fun subscribe(): ChunkSubscribers {
|
||||
val level = level
|
||||
check(level is ServerLevel) { "Invalid realm" }
|
||||
unsubscribe()
|
||||
@ -444,6 +442,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
subs.subscribe(this)
|
||||
_subCache = subs
|
||||
playerListUpdated = true
|
||||
return subs
|
||||
}
|
||||
|
||||
private class ChunkSubscribers(level: ServerLevel, val chunkPos: Long) {
|
||||
|
@ -21,56 +21,6 @@ import kotlin.collections.HashSet
|
||||
import kotlin.collections.LinkedHashSet
|
||||
import kotlin.math.ln
|
||||
|
||||
private class LinkedPriorityQueue<T : Comparable<T>> {
|
||||
private class Entry<T>(val value: T) {
|
||||
var next: Entry<T>? = null
|
||||
}
|
||||
|
||||
private var head: Entry<T>? = null
|
||||
|
||||
fun isNotEmpty(): Boolean {
|
||||
return head != null
|
||||
}
|
||||
|
||||
fun add(value: T) {
|
||||
if (head == null) {
|
||||
head = Entry(value)
|
||||
} else if (head!!.value >= value) {
|
||||
val entry = Entry(value)
|
||||
entry.next = head
|
||||
head = entry
|
||||
} else {
|
||||
var current = head
|
||||
var previous = current
|
||||
|
||||
while (current != null) {
|
||||
if (current.value >= value) {
|
||||
val entry = Entry(value)
|
||||
entry.next = current
|
||||
previous!!.next = entry
|
||||
return
|
||||
}
|
||||
|
||||
previous = current
|
||||
current = current.next
|
||||
}
|
||||
|
||||
previous!!.next = Entry(value)
|
||||
}
|
||||
}
|
||||
|
||||
fun remove(): T? {
|
||||
val head = head
|
||||
|
||||
if (head != null) {
|
||||
this.head = head.next
|
||||
return head.value
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableGraph>() {
|
||||
private val livelyNodes = HashSet<EnergyCableBlockEntity.Node>()
|
||||
private val livelyNodesList = ArrayList<EnergyCableBlockEntity.Node>()
|
||||
@ -385,13 +335,10 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
||||
v.segment.transferredLastTick = transferredLastTick
|
||||
v.segment.lastPoweredStatus = lastPoweredStatus
|
||||
v.segment.paths = paths.clone()
|
||||
|
||||
paths.forEach { it.segments.add(v.segment) }
|
||||
|
||||
result.add(v.segment)
|
||||
}
|
||||
|
||||
paths.forEach { it.nodes.addAll(nodes) }
|
||||
return result
|
||||
}
|
||||
}
|
||||
@ -471,16 +418,14 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
||||
return null
|
||||
}
|
||||
|
||||
val openNodes = LinkedPriorityQueue<SearchNode>()
|
||||
val openNodes = PriorityQueue<SearchNode>()
|
||||
val seenNodes = HashSet<EnergyCableBlockEntity.Node>()
|
||||
|
||||
openNodes.add(SearchNode(a, b, null, seenTop))
|
||||
|
||||
val existingNodes = HashSet<EnergyCableBlockEntity.Node>()
|
||||
existing.forEach { existingNodes.addAll(it.nodes) }
|
||||
|
||||
while (openNodes.isNotEmpty()) {
|
||||
val first = openNodes.remove()!!
|
||||
val first = openNodes.remove()
|
||||
openNodes.remove(first)
|
||||
|
||||
if (first.node === b) {
|
||||
// solution found
|
||||
@ -518,7 +463,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
||||
} else {
|
||||
for (neighbour in first.node.neighboursView.values) {
|
||||
if (!seenNodes.add(neighbour) || !neighbour.canTraverse) continue
|
||||
val seen = neighbour in existingNodes
|
||||
val seen = existing.any { neighbour in it }
|
||||
if (seen && neighbour.energyThroughput <= threshold) continue
|
||||
openNodes.add(SearchNode(neighbour, b, first, seen))
|
||||
}
|
||||
|
@ -66,9 +66,6 @@ class SynchableGroup : Observer, ISynchable, Iterable<ISynchable> {
|
||||
override val hasRemotes: Boolean
|
||||
get() = remotes.isNotEmpty()
|
||||
|
||||
val hasChildren: Boolean
|
||||
get() = slots.any { it != null }
|
||||
|
||||
override fun iterator(): Iterator<ISynchable> {
|
||||
return slots.iterator().map { it?.synchable }.filterNotNull()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user