Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
Properly Cancel Usable Items (#9225)
This fixes the bug causing canceling PlayerInteractEvent to cause items to continue to be used despite being canceled 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.
Dieser Commit ist enthalten in:
Ursprung
1f5bec71f3
Commit
3756f5bbf5
@ -8,16 +8,18 @@ Entities that are interacted with need to be resent to the client, so we resend
|
||||
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..bf6a70a69bb695ec1a202cd1e863c468329f80fc 100644
|
||||
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,46 @@ public class SynchedEntityData {
|
||||
@@ -253,14 +253,60 @@ public class SynchedEntityData {
|
||||
// CraftBukkit start
|
||||
public void refresh(ServerPlayer to) {
|
||||
if (!this.isEmpty()) {
|
||||
@ -61,6 +63,20 @@ index d088479d160dbd2fc90b48a30553be141db8eef2..bf6a70a69bb695ec1a202cd1e863c468
|
||||
+ 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> {
|
||||
|
40
patches/server/0978-Properly-Cancel-Usable-Items.patch
Normale Datei
40
patches/server/0978-Properly-Cancel-Usable-Items.patch
Normale Datei
@ -0,0 +1,40 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
||||
Date: Tue, 23 May 2023 22:33:36 -0400
|
||||
Subject: [PATCH] Properly Cancel Usable Items
|
||||
|
||||
This 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.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index 3ac28fb22efaec7621f8e42f998fd84bbff9ec91..2a609e43370e68943c580083f7f7d8c9b0972955 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -2029,6 +2029,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
||||
}
|
||||
|
||||
if (cancelled) {
|
||||
+ this.player.resyncUsingItem(this.player); // Paper - Resend player's using item status
|
||||
this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
|
||||
return;
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index a189461330a4d427a7450d504ef13de3605497e3..064bd3f2615009b3f15f3a5006f0b5f7a7ba6bf5 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -3758,6 +3758,12 @@ 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
|
||||
+ public void resyncUsingItem(ServerPlayer serverPlayer) {
|
||||
+ this.getEntityData().resendPossiblyDesyncedDataValues(java.util.List.of(DATA_LIVING_ENTITY_FLAGS), serverPlayer);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
// Paper start - lag compensate eating
|
||||
protected long eatStartTime;
|
||||
protected int totalEatTimeTicks;
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren