If blockentity is ticking, don't synchronize to newly subscribed players right away
This commit is contained in:
parent
f0f1a3cffe
commit
77e6eebe92
@ -642,12 +642,14 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
playerListUpdated = false
|
playerListUpdated = false
|
||||||
|
|
||||||
for (player in subscription.players) {
|
for (player in subscription.players) {
|
||||||
|
if (player !in subscription.veto) {
|
||||||
val payload = synchronizer.computeEndpointFor(player).collectNetworkPayload()
|
val payload = synchronizer.computeEndpointFor(player).collectNetworkPayload()
|
||||||
|
|
||||||
if (payload != null) {
|
if (payload != null) {
|
||||||
GenericNetworkChannel.send(player, BlockEntitySyncPacket(blockPos, payload.array, payload.length))
|
GenericNetworkChannel.send(player, BlockEntitySyncPacket(blockPos, payload.array, payload.length))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
synchronizer.markClean()
|
synchronizer.markClean()
|
||||||
} else if (calledBySynchronizer) {
|
} else if (calledBySynchronizer) {
|
||||||
@ -662,6 +664,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
val level = WeakReference(level)
|
val level = WeakReference(level)
|
||||||
val blockEntities = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0)
|
val blockEntities = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0)
|
||||||
val players = ObjectLinkedOpenHashSet<ServerPlayer>(0)
|
val players = ObjectLinkedOpenHashSet<ServerPlayer>(0)
|
||||||
|
val veto = ObjectLinkedOpenHashSet<ServerPlayer>(0)
|
||||||
val blockEntitiesWithObservers = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0)
|
val blockEntitiesWithObservers = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0)
|
||||||
|
|
||||||
operator fun component1() = blockEntities
|
operator fun component1() = blockEntities
|
||||||
@ -673,9 +676,12 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
|
|
||||||
fun subscribe(player: ServerPlayer) {
|
fun subscribe(player: ServerPlayer) {
|
||||||
if (players.add(player)) {
|
if (players.add(player)) {
|
||||||
blockEntities.forEach { it.playerListUpdated = true }
|
veto.add(player)
|
||||||
|
|
||||||
onceServer(10) {
|
onceServer(10) {
|
||||||
|
veto.remove(player)
|
||||||
|
blockEntities.forEach { it.playerListUpdated = true }
|
||||||
|
|
||||||
if (!player.hasDisconnected() && player in players) {
|
if (!player.hasDisconnected() && player in players) {
|
||||||
blockEntities.forEach {
|
blockEntities.forEach {
|
||||||
it.synchronizeToPlayers(false)
|
it.synchronizeToPlayers(false)
|
||||||
@ -687,6 +693,8 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
|
|
||||||
fun unsubscribe(player: ServerPlayer): Boolean {
|
fun unsubscribe(player: ServerPlayer): Boolean {
|
||||||
if (players.remove(player)) {
|
if (players.remove(player)) {
|
||||||
|
veto.remove(player)
|
||||||
|
|
||||||
blockEntities.forEach {
|
blockEntities.forEach {
|
||||||
it.synchronizer.removeEndpointFor(player)
|
it.synchronizer.removeEndpointFor(player)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user