aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0974-Properly-Cancel-Usable-Items.patch
blob: 45da59d385426c454abf8e4c5a3a56ce69043f50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 1d0e439c00ac4ab72dc656038c9271b1240acc88..b777547cb9f8edf4e7b3c2cfb894f8cd1b1a35a5 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 dee49691dcaac57ab56195a4dd299a5c23a56bbb..e11d7283662834047b2ff81a2fd25a4263792deb 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3748,6 +3748,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;