diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt index 59d9efe96..40941bf09 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt @@ -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) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/network/syncher/SynchableGroup.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/network/syncher/SynchableGroup.kt index bc3ee3c78..9b5ad3f04 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/network/syncher/SynchableGroup.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/network/syncher/SynchableGroup.kt @@ -66,6 +66,9 @@ class SynchableGroup : Observer, ISynchable, Iterable { override val hasRemotes: Boolean get() = remotes.isNotEmpty() + val hasChildren: Boolean + get() = slots.any { it != null } + override fun iterator(): Iterator { return slots.iterator().map { it?.synchable }.filterNotNull() }