From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Fri, 24 May 2024 19:03:02 +0800 Subject: [PATCH] Tracking Optimize: Skip redundant useless packets Removed since 1.21, not good, useless diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java index c2db18cbb1230588e6b1783dc51c69ed3ccd2e34..71a7b36f7ab1d0743591495a45d8a153cee138e8 100644 --- a/src/main/java/net/minecraft/server/level/ServerEntity.java +++ b/src/main/java/net/minecraft/server/level/ServerEntity.java @@ -418,23 +418,34 @@ public class ServerEntity { // Paper end } + // Leaf start - Tracking Optimize - Skip redundant useless packets + private List> lastSendDirtyData = new ArrayList<>(); + private Set lastSendDirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet(); + // Leaf end - Tracking Optimize - Skip redundant useless packets private void sendDirtyEntityData() { SynchedEntityData datawatcher = this.entity.getEntityData(); List> list = datawatcher.packDirty(); if (list != null) { this.trackedDataValues = datawatcher.getNonDefaultValues(); + // Leaf start - Tracking Optimize - Skip redundant useless packets + if (!lastSendDirtyData.equals(list)) { // Leaf start - petal - sync ((ServerLevel) this.entity.level()).chunkSource.chunkMap.runOnTrackerMainThread(() -> this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), list)) ); // Leaf end - petal + lastSendDirtyData = new ArrayList<>(list); + } + // Leaf end - Tracking Optimize - Skip redundant useless packets } if (this.entity instanceof LivingEntity) { Set set = ((LivingEntity) this.entity).getAttributes().getDirtyAttributes(); if (!set.isEmpty()) { + // Leaf start - Tracking Optimize - Skip redundant useless packets + if (!lastSendDirtyAttributes.equals(set)) { // Leaf start - petal - sync final Set copy = com.google.common.collect.Sets.newConcurrentHashSet(set); ((ServerLevel) this.entity.level()).chunkSource.chunkMap.runOnTrackerMainThread(() -> { @@ -447,6 +458,9 @@ public class ServerEntity { }); // Leaf end - petal + lastSendDirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet(set); + } + // Leaf end - Tracking Optimize - Skip redundant useless packets } ((LivingEntity) this.entity).getAttributes().clearDirtyAttributes(); // Leaf