mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
aee3dfd092
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: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
273 lines
17 KiB
Diff
273 lines
17 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.
|
|
|
|
This also also fixes the bug causing cancelling PlayerInteractEvent to cause items to continue
|
|
to be used despite being cancelled on the server.
|
|
|
|
For example, items being consumed but never finishing, shields being put up, etc.
|
|
The underlying issue of this is that the client modifies their synced data values,
|
|
and so we have to (forcibly) resend them in order for the client to reset their using item state.
|
|
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
+++ b/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
@@ -0,0 +0,0 @@ public class SynchedEntityData {
|
|
}
|
|
}
|
|
|
|
- private <T> SynchedEntityData.DataItem<T> getItem(EntityDataAccessor<T> key) {
|
|
+ public <T> SynchedEntityData.DataItem<T> getItem(EntityDataAccessor<T> key) { // Paper - public
|
|
return (SynchedEntityData.DataItem<T>) this.itemsById[key.id()]; // CraftBukkit - decompile error
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ public class SynchedEntityData {
|
|
}
|
|
}
|
|
|
|
+ // 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
|
|
+ public List<SynchedEntityData.DataValue<?>> packAll() {
|
|
+ final List<SynchedEntityData.DataValue<?>> list = new ArrayList<>();
|
|
+ for (final DataItem<?> dataItem : this.itemsById) {
|
|
+ list.add(dataItem.value());
|
|
+ }
|
|
+
|
|
+ return list;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public static class DataItem<T> {
|
|
|
|
final EntityDataAccessor<T> accessor;
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -0,0 +0,0 @@ public class ServerPlayerGameMode {
|
|
}
|
|
// Paper end - extend Player Interact cancellation
|
|
player.getBukkitEntity().updateInventory(); // SPIGOT-2867
|
|
+ this.player.resyncUsingItem(this.player); // Paper - Properly cancel usable items
|
|
return (event.useItemInHand() != Event.Result.ALLOW) ? InteractionResult.SUCCESS : InteractionResult.PASS;
|
|
} else if (this.gameModeForPlayer == GameType.SPECTATOR) {
|
|
MenuProvider itileinventory = iblockdata.getMenuProvider(world, blockposition);
|
|
@@ -0,0 +0,0 @@ public class ServerPlayerGameMode {
|
|
|
|
return enuminteractionresult;
|
|
} else {
|
|
+ // Paper start - Properly cancel usable items; Cancel only if cancelled + if the interact result is different from default response
|
|
+ if (this.interactResult && this.interactResult != cancelledItem) {
|
|
+ this.player.resyncUsingItem(this.player);
|
|
+ }
|
|
+ // Paper end - Properly cancel usable items
|
|
return InteractionResult.PASS;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
}
|
|
|
|
if (cancelled) {
|
|
+ this.player.resyncUsingItem(this.player); // Paper - Properly cancel usable items
|
|
this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
|
|
return;
|
|
}
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
// 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)) {
|
|
- entity.getBukkitEntity().update(ServerGamePacketListenerImpl.this.player);
|
|
+ entity.resendPossiblyDesyncedEntityData(ServerGamePacketListenerImpl.this.player); // Paper - The entire mob gets deleted, so resend it
|
|
ServerGamePacketListenerImpl.this.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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
((ServerLevel)player.level()).getChunkSource().chunkMap.addEntity(player); // Paper - Fire PlayerJoinEvent when Player is actually ready; track entity now
|
|
// CraftBukkit end
|
|
|
|
- player.refreshEntityData(player); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn
|
|
+ //player.refreshEntityData(player); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn // Paper - THIS IS NOT NEEDED ANYMORE
|
|
|
|
this.sendLevelInfo(player, worldserver1);
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
public void sendActiveEffects(LivingEntity entity, ServerGamePacketListenerImpl networkHandler) {
|
|
+ // Paper start - collect packets
|
|
+ this.sendActiveEffects(entity, networkHandler::send);
|
|
+ }
|
|
+ public void sendActiveEffects(LivingEntity entity, java.util.function.Consumer<Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> packetConsumer) {
|
|
+ // Paper end - collect packets
|
|
Iterator iterator = entity.getActiveEffects().iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
|
|
|
|
- networkHandler.send(new ClientboundUpdateMobEffectPacket(entity.getId(), mobeffect, false));
|
|
+ packetConsumer.accept(new ClientboundUpdateMobEffectPacket(entity.getId(), mobeffect, false)); // Paper - collect packets
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
|
|
// CraftBukkit start
|
|
public void refreshEntityData(ServerPlayer to) {
|
|
- List<SynchedEntityData.DataValue<?>> list = this.getEntityData().getNonDefaultValues();
|
|
+ List<SynchedEntityData.DataValue<?>> list = this.entityData.packAll(); // Paper - Update EVERYTHING not just not default
|
|
|
|
- if (list != null) {
|
|
+ if (list != null && to.getBukkitEntity().canSee(this.getBukkitEntity())) { // Paper
|
|
to.connection.send(new ClientboundSetEntityDataPacket(this.getId(), list));
|
|
}
|
|
}
|
|
// CraftBukkit end
|
|
+ // Paper start
|
|
+ // This method should only be used if the data of an entity could have become desynced
|
|
+ // due to interactions on the client.
|
|
+ public void resendPossiblyDesyncedEntityData(net.minecraft.server.level.ServerPlayer player) {
|
|
+ if (player.getBukkitEntity().canSee(this.getBukkitEntity())) {
|
|
+ ServerLevel world = (net.minecraft.server.level.ServerLevel)this.level();
|
|
+ net.minecraft.server.level.ChunkMap.TrackedEntity tracker = world == null ? null : world.getChunkSource().chunkMap.entityMap.get(this.getId());
|
|
+ if (tracker == null) {
|
|
+ return;
|
|
+ }
|
|
+ final net.minecraft.server.level.ServerEntity serverEntity = tracker.serverEntity;
|
|
+ final List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> list = new java.util.ArrayList<>();
|
|
+ serverEntity.sendPairingData(player, list::add);
|
|
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundBundlePacket(list));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // 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.getBukkitEntity())) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ final List<SynchedEntityData.DataValue<?>> values = new java.util.ArrayList<>(keys.size());
|
|
+ for (final EntityDataAccessor<?> key : keys) {
|
|
+ final SynchedEntityData.DataItem<?> synchedValue = this.entityData.getItem(key);
|
|
+ values.add(synchedValue.value());
|
|
+ }
|
|
+
|
|
+ to.connection.send(new ClientboundSetEntityDataPacket(this.id, values));
|
|
+ }
|
|
+ // Paper end
|
|
|
|
public boolean equals(Object object) {
|
|
return object instanceof Entity ? ((Entity) object).id == this.id : false;
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
return ((Byte) this.entityData.get(LivingEntity.DATA_LIVING_ENTITY_FLAGS) & 2) > 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
|
|
}
|
|
|
|
+ // Paper start - Properly cancel usable items
|
|
+ public void resyncUsingItem(ServerPlayer serverPlayer) {
|
|
+ this.resendPossiblyDesyncedDataValues(java.util.List.of(DATA_LIVING_ENTITY_FLAGS), serverPlayer);
|
|
+ }
|
|
+ // Paper end - Properly cancel usable items
|
|
private void updatingUsingItem() {
|
|
if (this.isUsingItem()) {
|
|
if (ItemStack.isSameItem(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Bucketable.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Bucketable.java
|
|
@@ -0,0 +0,0 @@ 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
|
|
- entity.getBukkitEntity().update((ServerPlayer) player); // We need to play out these packets as the client assumes the fish is gone
|
|
- entity.refreshEntityData((ServerPlayer) player); // Need to send data such as the display name to client
|
|
+ entity.resendPossiblyDesyncedEntityData((ServerPlayer) player); // Paper
|
|
return Optional.of(InteractionResult.FAIL);
|
|
}
|
|
entity.playSound(((Bucketable) entity).getPickupSound(), 1.0F, 1.0F);
|
|
diff --git a/src/main/java/net/minecraft/world/item/SuspiciousStewItem.java b/src/main/java/net/minecraft/world/item/SuspiciousStewItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/SuspiciousStewItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/SuspiciousStewItem.java
|
|
@@ -0,0 +0,0 @@ public class SuspiciousStewItem extends Item {
|
|
public void cancelUsingItem(net.minecraft.server.level.ServerPlayer entityplayer, ItemStack itemstack) {
|
|
SuspiciousStewEffects suspicioussteweffects = (SuspiciousStewEffects) itemstack.getOrDefault(DataComponents.SUSPICIOUS_STEW_EFFECTS, SuspiciousStewEffects.EMPTY);
|
|
|
|
+ final List<net.minecraft.network.protocol.Packet<? super net.minecraft.network.protocol.game.ClientGamePacketListener>> packets = new java.util.ArrayList<>(); // Paper - bundlize packets
|
|
for (SuspiciousStewEffects.Entry suspicioussteweffects_a : suspicioussteweffects.effects()) {
|
|
- entityplayer.connection.send(new net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket(entityplayer.getId(), suspicioussteweffects_a.effect()));
|
|
+ packets.add(new net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket(entityplayer.getId(), suspicioussteweffects_a.effect())); // Paper - bundlize packets
|
|
}
|
|
- entityplayer.server.getPlayerList().sendActivePlayerEffects(entityplayer);
|
|
+ // Paper start - bundlize packets
|
|
+ entityplayer.server.getPlayerList().sendActiveEffects(entityplayer, packets::add);
|
|
+ entityplayer.connection.send(new net.minecraft.network.protocol.game.ClientboundBundlePacket(packets));
|
|
+ // Paper end - bundlize packets
|
|
}
|
|
// CraftBukkit end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -0,0 +0,0 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
return;
|
|
}
|
|
|
|
- entityTracker.broadcast(this.getHandle().getAddEntityPacket(entityTracker.serverEntity));
|
|
+ // Paper start - resend possibly desynced entity instead of add entity packet
|
|
+ for (final ServerPlayerConnection connection : entityTracker.seenBy) {
|
|
+ this.getHandle().resendPossiblyDesyncedEntityData(connection.getPlayer());
|
|
+ }
|
|
+ // Paper end - resend possibly desynced entity instead of add entity packet
|
|
}
|
|
|
|
public void update(ServerPlayer player) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java
|
|
@@ -0,0 +0,0 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
|
|
protected void update() {
|
|
super.update();
|
|
|
|
+ // Paper start, don't mark as dirty as this is handled in super.update()
|
|
// mark dirty, so that the client gets updated with item and rotation
|
|
- this.getHandle().getEntityData().markDirty(net.minecraft.world.entity.decoration.ItemFrame.DATA_ITEM);
|
|
- this.getHandle().getEntityData().markDirty(net.minecraft.world.entity.decoration.ItemFrame.DATA_ROTATION);
|
|
+ //this.getHandle().getEntityData().markDirty(net.minecraft.world.entity.decoration.ItemFrame.DATA_ITEM);
|
|
+ //this.getHandle().getEntityData().markDirty(net.minecraft.world.entity.decoration.ItemFrame.DATA_ROTATION);
|
|
+ // Paper end
|
|
|
|
// update redstone
|
|
if (!this.getHandle().generation) {
|