aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0777-Correctly-shrink-items-during-EntityResurrectEvent.patch
blob: 4f1878d01560ae69ed627602fffa67f6f12e4288 (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bjarne Koll <git@lynxplay.dev>
Date: Tue, 10 Jan 2023 21:06:42 +0100
Subject: [PATCH] Correctly shrink items during EntityResurrectEvent

The EntityResurrectEvent logic is supposed to locate a totem of undying
in any of the interaction slots of the player inventory and then, if the
called EntityResurrectEvent is not cancelled, shrink that item by 1,
usually reducing it to zero.

For this, the logic iterates over the items in the interaction slots and
breaks out the loop if a totem of undying was found.
However, even if no totem of undying was found, the iteration item stack
variable remains as a refernce to the last interaction slot probed.

Plugins uncancelling a EntityResurrectEvent, which is published
pre-cancelled to listeners if no totem of undying could be found,
would hence cause the server logic to shrink completely unrelated items
found in, at the writing of this patch, the players off hand slot.

This patch corrects this behaviour by only shrinking the item if a totem
of undying was found and the event was called uncancelled.

diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index b2c94edf9e1161aa97aa56f4124d96bd6a9b42ce..ff583a2c502f700b60cfe4a7fc341744d86f1c32 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1683,7 +1683,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
             this.level().getCraftServer().getPluginManager().callEvent(event);
 
             if (!event.isCancelled()) {
-                if (!itemstack1.isEmpty()) {
+                if (!itemstack1.isEmpty() && itemstack != null) { // Paper - only reduce item if actual totem was found
                     itemstack1.shrink(1);
                 }
                 if (itemstack != null && this instanceof ServerPlayer) {