Don't subscribe block entity to chunk if syncher has no entries

This commit is contained in:
DBotThePony 2025-02-11 13:49:48 +07:00
parent 483c27d919
commit 486060c8a4
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 7 additions and 3 deletions

View File

@ -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) {

View File

@ -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()
}