Compare commits
5 Commits
fdc9944c17
...
486060c8a4
Author | SHA1 | Date | |
---|---|---|---|
486060c8a4 | |||
483c27d919 | |||
89ca0fbce8 | |||
590f420c07 | |||
18949d65c4 |
@ -413,7 +413,6 @@ 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() {
|
||||
@ -430,7 +429,10 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
||||
playerListUpdated = false
|
||||
}
|
||||
|
||||
private fun subscribe(): ChunkSubscribers {
|
||||
private fun subscribe() {
|
||||
if (!syncher.hasChildren)
|
||||
return
|
||||
|
||||
val level = level
|
||||
check(level is ServerLevel) { "Invalid realm" }
|
||||
unsubscribe()
|
||||
@ -442,7 +444,6 @@ 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,6 +21,56 @@ 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>()
|
||||
@ -335,10 +385,13 @@ 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
|
||||
}
|
||||
}
|
||||
@ -418,14 +471,16 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
||||
return null
|
||||
}
|
||||
|
||||
val openNodes = PriorityQueue<SearchNode>()
|
||||
val openNodes = LinkedPriorityQueue<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()
|
||||
openNodes.remove(first)
|
||||
val first = openNodes.remove()!!
|
||||
|
||||
if (first.node === b) {
|
||||
// solution found
|
||||
@ -463,7 +518,7 @@ class EnergyCableGraph : GraphNodeList<EnergyCableBlockEntity.Node, EnergyCableG
|
||||
} else {
|
||||
for (neighbour in first.node.neighboursView.values) {
|
||||
if (!seenNodes.add(neighbour) || !neighbour.canTraverse) continue
|
||||
val seen = existing.any { neighbour in it }
|
||||
val seen = neighbour in existingNodes
|
||||
if (seen && neighbour.energyThroughput <= threshold) continue
|
||||
openNodes.add(SearchNode(neighbour, b, first, seen))
|
||||
}
|
||||
|
@ -66,6 +66,9 @@ 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