mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
c0936a71bd
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: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
124 lines
7.0 KiB
Diff
124 lines
7.0 KiB
Diff
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.
|
|
|
|
See: https://github.com/PaperMC/Paper/pull/1896
|
|
|
|
== AT ==
|
|
public net.minecraft.server.level.ChunkMap$TrackedEntity serverEntity
|
|
|
|
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
|
|
--- 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 {
|
|
// 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())) {
|
|
+ serverEntity.sendPairingData(player, player.connection::send);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // 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));
|
|
+ }
|
|
+ // 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 c60906e122e058a19248b0e629531d8ec27146ca..bd3dcc1e126c91644fb0a23423d0f6d1c32f3352 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2799,7 +2799,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
|
|
// 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
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -371,7 +371,7 @@ public abstract class PlayerList {
|
|
((ServerLevel)player.level()).getChunkSource().chunkMap.addEntity(player); // Paper - track entity now
|
|
// 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
|
|
|
|
this.sendLevelInfo(player, worldserver1);
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/Bucketable.java b/src/main/java/net/minecraft/world/entity/animal/Bucketable.java
|
|
index 37596c7b65f280be00e8e59ae18bd1aceae21080..eca18540aeb0b0d4098477d73b14c78a7bf9f455 100644
|
|
--- 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);
|