Don't subscribe block entity to chunk if syncher has no entries
This commit is contained in:
parent
483c27d919
commit
486060c8a4
@ -413,7 +413,6 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var _subCache: ChunkSubscribers? = null
|
private var _subCache: ChunkSubscribers? = null
|
||||||
private val subscription get() = _subCache ?: subscribe()
|
|
||||||
private var playerListUpdated = false
|
private var playerListUpdated = false
|
||||||
|
|
||||||
private fun unsubscribe() {
|
private fun unsubscribe() {
|
||||||
@ -430,7 +429,10 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
playerListUpdated = false
|
playerListUpdated = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun subscribe(): ChunkSubscribers {
|
private fun subscribe() {
|
||||||
|
if (!syncher.hasChildren)
|
||||||
|
return
|
||||||
|
|
||||||
val level = level
|
val level = level
|
||||||
check(level is ServerLevel) { "Invalid realm" }
|
check(level is ServerLevel) { "Invalid realm" }
|
||||||
unsubscribe()
|
unsubscribe()
|
||||||
@ -442,7 +444,6 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
subs.subscribe(this)
|
subs.subscribe(this)
|
||||||
_subCache = subs
|
_subCache = subs
|
||||||
playerListUpdated = true
|
playerListUpdated = true
|
||||||
return subs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ChunkSubscribers(level: ServerLevel, val chunkPos: Long) {
|
private class ChunkSubscribers(level: ServerLevel, val chunkPos: Long) {
|
||||||
|
@ -66,6 +66,9 @@ class SynchableGroup : Observer, ISynchable, Iterable<ISynchable> {
|
|||||||
override val hasRemotes: Boolean
|
override val hasRemotes: Boolean
|
||||||
get() = remotes.isNotEmpty()
|
get() = remotes.isNotEmpty()
|
||||||
|
|
||||||
|
val hasChildren: Boolean
|
||||||
|
get() = slots.any { it != null }
|
||||||
|
|
||||||
override fun iterator(): Iterator<ISynchable> {
|
override fun iterator(): Iterator<ISynchable> {
|
||||||
return slots.iterator().map { it?.synchable }.filterNotNull()
|
return slots.iterator().map { it?.synchable }.filterNotNull()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user