Paper/patches/server/0907-Properly-resend-entities.patch

124 lines
7.0 KiB
Diff
Raw Normal View History

2022-12-08 00:11:44 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Wed, 7 Dec 2022 17:25:19 -0500
Subject: [PATCH] Properly resend entities
This resolves some issues which caused entities to not be resent correctly.
Entities that are interacted with need to be resent to the client, so we resend all the entity
data to the player whilst making sure not to clear dirty entries from the tracker. This makes
sure that values will be correctly updated to other players.
This also adds utilities to aid in further preventing entity desyncs.
2022-12-08 00:11:44 +01:00
See: https://github.com/PaperMC/Paper/pull/1896
== AT ==
2022-12-08 12:00:10 +01:00
public net.minecraft.server.level.ChunkMap$TrackedEntity serverEntity
2022-12-08 00:11:44 +01:00
diff --git a/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java b/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
index d088479d160dbd2fc90b48a30553be141db8eef2..15add3f4dfd718ec09bb1db4f22223466936879c 100644
2022-12-08 00:11:44 +01:00
--- a/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
+++ b/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
@@ -253,14 +253,60 @@ public class SynchedEntityData {
2022-12-08 00:11:44 +01:00
// CraftBukkit start
public void refresh(ServerPlayer to) {
if (!this.isEmpty()) {
- List<SynchedEntityData.DataValue<?>> list = this.getNonDefaultValues();
+ List<SynchedEntityData.DataValue<?>> list = this.packAll(); // Paper - Update EVERYTHING not just not default
if (list != null) {
+ if (to.getBukkitEntity().canSee(this.entity.getBukkitEntity())) { // Paper
to.connection.send(new ClientboundSetEntityDataPacket(this.entity.getId(), list));
+ } // Paper
}
}
}
// CraftBukkit end
+ // Paper start
+ // We need to pack all as we cannot rely on "non default values" or "dirty" ones.
+ // Because these values can possibly be desynced on the client.
+ @Nullable
+ private List<SynchedEntityData.DataValue<?>> packAll() {
+ if (this.isEmpty()) {
+ return null;
+ }
+
+ List<SynchedEntityData.DataValue<?>> list = new ArrayList<>();
+ for (DataItem<?> dataItem : this.itemsById.values()) {
+ list.add(dataItem.value());
+ }
+
+ return list;
+ }
+
+ // This method should only be used if the data of an entity could have became desynced
+ // due to interactions on the client.
+ public void resendPossiblyDesyncedEntity(ServerPlayer player) {
+ if (this.entity.tracker == null) {
+ return;
+ }
+
+ net.minecraft.server.level.ServerEntity serverEntity = this.entity.tracker.serverEntity;
+ if (player.getBukkitEntity().canSee(entity.getBukkitEntity())) {
2023-06-08 22:56:13 +02:00
+ serverEntity.sendPairingData(player, player.connection::send);
2022-12-08 00:11:44 +01:00
+ }
+ }
+
+ // This method allows you to specifically resend certain data accessor keys to the client
+ public void resendPossiblyDesyncedDataValues(List<EntityDataAccessor<?>> keys, ServerPlayer to) {
+ if (!to.getBukkitEntity().canSee(this.entity.getBukkitEntity())) {
+ return;
+ }
+ List<SynchedEntityData.DataValue<?>> values = new ArrayList<>(keys.size());
+ for (EntityDataAccessor<?> key : keys) {
+ SynchedEntityData.DataItem<?> synchedValue = this.getItem(key);
+ values.add(synchedValue.value());
+ }
+
+ to.connection.send(new ClientboundSetEntityDataPacket(this.entity.getId(), values));
+ }
2022-12-08 00:11:44 +01:00
+ // Paper end
public static class DataItem<T> {
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 7bb601078ef3a983d1807246b91b669ae5d5a8e4..dbc93883b8529b0aab3ea21ddd466bc8c3739351 100644
2022-12-08 00:11:44 +01:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
Updated Upstream (Bukkit/CraftBukkit) (#9485) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 82af5dc6 SPIGOT-7396: Add PlayerSignOpenEvent 3f0281ca SPIGOT-7063, PR-763: Add DragonBattle#initiateRespawn with custom EnderCrystals f83c8df4 PR-873: Add PlayerRecipeBookClickEvent 14560d39 SPIGOT-7435: Add TeleportCause#EXIT_BED 2cc6db92 SPIGOT-7422, PR-887: Add API to set sherds on decorated pots 36022f02 PR-883: Add ItemFactory#getSpawnEgg 12eb5c46 PR-881: Update Scoreboard Javadocs, remove explicit exception throwing f6d8d44a PR-882: Add modern time API methods to ban API 21a7b710 Upgrade some Maven plugins to reduce warnings 11fd1225 PR-886: Deprecate the SmithingRecipe constructor as it now does nothing dbd1761d SPIGOT-7406: Improve documentation for getDragonBattle CraftBukkit Changes: d548daac2 SPIGOT-7446: BlockState#update not updating a spawner's type to null 70e0bc050 SPIGOT-7447: Fix --forceUpgrade 6752f1d63 SPIGOT-7396: Add PlayerSignOpenEvent 847b4cad5 SPIGOT-7063, PR-1071: Add DragonBattle#initiateRespawn with custom EnderCrystals c335a555f PR-1212: Add PlayerRecipeBookClickEvent 4be756ecb SPIGOT-7445: Fix opening smithing inventory db70bd6ed SPIGOT-7441: Fix issue placing certain items in creative/op f7fa6d993 SPIGOT-7435: Add TeleportCause#EXIT_BED b435e8e8d SPIGOT-7349: Player#setDisplayName not working when message/format unmodified a2fafdd1d PR-1232: Re-add fix for player rotation 7cf863de1 PR-1233: Remove some old MC bug fixes now fixed in vanilla 08ec344ad Fix ChunkGenerator#generateCaves never being called 5daeb502a SPIGOT-7422, PR-1228: Add API to set sherds on decorated pots 52faa6b32 PR-1224: Add ItemFactory#getSpawnEgg 01cae71b7 SPIGOT-7429: Fix LEFT_CLICK_AIR not working for passable entities and spectators a94277a18 PR-1223: Remove non-existent scoreboard display name/prefix/suffix limits 36b107660 PR-1225: Add modern time API methods to ban API 59ead25bc Upgrade some Maven plugins to reduce warnings 202fc5c4e Increase outdated build delay ce545de57 SPIGOT-7398: TextDisplay#setInterpolationDuration incorrectly updates the line width Spigot Changes: b41c46db Rebuild patches 3374045a SPIGOT-7431: Fix EntityMountEvent returning opposite entities 0ca4eb66 Rebuild patches
2023-08-06 02:21:59 +02:00
@@ -2805,7 +2805,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-12-08 00:11:44 +01:00
// Entity in bucket - SPIGOT-4048 and SPIGOT-6859a
if ((entity instanceof Bucketable && entity instanceof LivingEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET) && (event.isCancelled() || ServerGamePacketListenerImpl.this.player.getInventory().getSelected() == null || ServerGamePacketListenerImpl.this.player.getInventory().getSelected().getItem() != origItem)) {
- ServerGamePacketListenerImpl.this.send(new ClientboundAddEntityPacket(entity));
+ entity.getEntityData().resendPossiblyDesyncedEntity(player); // Paper - The entire mob gets deleted, so resend it.
player.containerMenu.sendAllDataToRemote();
}
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 815eb218b6612b13c6deff636509bad35eeace62..490f2d6f7a43d0a5915a80960c1c7c48b3eea19f 100644
2022-12-08 00:11:44 +01:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2023-06-08 10:47:19 +02:00
@@ -371,7 +371,7 @@ public abstract class PlayerList {
((ServerLevel)player.level()).getChunkSource().chunkMap.addEntity(player); // Paper - track entity now
2022-12-08 00:11:44 +01:00
// CraftBukkit end
- player.getEntityData().refresh(player); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn
+ //player.getEntityData().refresh(player); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn Paper - THIS IS NOT NEEDED ANYMORE
2023-03-14 22:29:14 +01:00
this.sendLevelInfo(player, worldserver1);
2022-12-08 00:11:44 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/animal/Bucketable.java b/src/main/java/net/minecraft/world/entity/animal/Bucketable.java
2023-06-08 10:47:19 +02:00
index 37596c7b65f280be00e8e59ae18bd1aceae21080..eca18540aeb0b0d4098477d73b14c78a7bf9f455 100644
2022-12-08 00:11:44 +01:00
--- a/src/main/java/net/minecraft/world/entity/animal/Bucketable.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Bucketable.java
@@ -109,8 +109,7 @@ public interface Bucketable {
itemstack1 = CraftItemStack.asNMSCopy(playerBucketFishEvent.getEntityBucket());
if (playerBucketFishEvent.isCancelled()) {
((ServerPlayer) player).containerMenu.sendAllDataToRemote(); // We need to update inventory to resync client's bucket
- ((ServerPlayer) player).connection.send(new ClientboundAddEntityPacket(entity)); // We need to play out these packets as the client assumes the fish is gone
- entity.getEntityData().refresh((ServerPlayer) player); // Need to send data such as the display name to client
+ entity.getEntityData().resendPossiblyDesyncedEntity((ServerPlayer) player); // Paper
return Optional.of(InteractionResult.FAIL);
}
entity.playSound(((Bucketable) entity).getPickupSound(), 1.0F, 1.0F);