Try to avoid synchronization when no players are listening

This commit is contained in:
DBotThePony 2022-10-12 10:00:46 +07:00
parent f6cf694967
commit d1d35f0730
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -25,13 +25,19 @@ import java.util.WeakHashMap
abstract class SynchronizedBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: BlockPos, p_155230_: BlockState) : BlockEntity(p_155228_, p_155229_, p_155230_) { abstract class SynchronizedBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: BlockPos, p_155230_: BlockState) : BlockEntity(p_155228_, p_155229_, p_155230_) {
val synchronizer = FieldSynchronizer { val synchronizer = FieldSynchronizer {
if (!isRemoved && level?.isClientSide == false) { if (!isRemoved && level?.isClientSide == false && (_subCache == null || (_subCache ?: throw ConcurrentModificationException()).players.isNotEmpty())) {
onceServer { onceServer {
synchronizeToPlayers(true) synchronizeToPlayers(true)
} }
} else {
markSynchronizerClean()
} }
} }
private fun markSynchronizerClean() {
synchronizer.markClean()
}
init { init {
synchronizer.defaultEndpoint.markUnused() synchronizer.defaultEndpoint.markUnused()
} }