mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
c613877e54
Although vanilla does not specifically call this method anywhere, this fixes a bug where the result using the Bukkit API returns the wrong amount.
41 lines
2.3 KiB
Diff
41 lines
2.3 KiB
Diff
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;
|