If blockentity is ticking, don't synchronize to newly subscribed players right away

This commit is contained in:
DBotThePony 2023-08-17 14:15:27 +07:00
parent f0f1a3cffe
commit 77e6eebe92
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -642,10 +642,12 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
playerListUpdated = false
for (player in subscription.players) {
val payload = synchronizer.computeEndpointFor(player).collectNetworkPayload()
if (player !in subscription.veto) {
val payload = synchronizer.computeEndpointFor(player).collectNetworkPayload()
if (payload != null) {
GenericNetworkChannel.send(player, BlockEntitySyncPacket(blockPos, payload.array, payload.length))
if (payload != null) {
GenericNetworkChannel.send(player, BlockEntitySyncPacket(blockPos, payload.array, payload.length))
}
}
}
@ -662,6 +664,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
val level = WeakReference(level)
val blockEntities = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0)
val players = ObjectLinkedOpenHashSet<ServerPlayer>(0)
val veto = ObjectLinkedOpenHashSet<ServerPlayer>(0)
val blockEntitiesWithObservers = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0)
operator fun component1() = blockEntities
@ -673,9 +676,12 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
fun subscribe(player: ServerPlayer) {
if (players.add(player)) {
blockEntities.forEach { it.playerListUpdated = true }
veto.add(player)
onceServer(10) {
veto.remove(player)
blockEntities.forEach { it.playerListUpdated = true }
if (!player.hasDisconnected() && player in players) {
blockEntities.forEach {
it.synchronizeToPlayers(false)
@ -687,6 +693,8 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
fun unsubscribe(player: ServerPlayer): Boolean {
if (players.remove(player)) {
veto.remove(player)
blockEntities.forEach {
it.synchronizer.removeEndpointFor(player)
}