mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-28 18:52:03 -07: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.
This commit is contained in:
@@ -8,6 +8,8 @@ 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 ==
|
||||
@@ -61,6 +63,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ 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> {
|
||||
|
Reference in New Issue
Block a user