aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjarne Koll <[email protected]>2023-11-17 07:43:25 +0100
committerGitHub <[email protected]>2023-11-17 07:43:25 +0100
commit0a8c87372246f2bc06b54f488003748f1aa7f219 (patch)
tree646e333bf28d036c7cf609c0f1541f1a98e8c7dc
parentce7f0680956bb1c779ac4db9fe0fd1f00bb35bae (diff)
downloadPaper-0a8c87372246f2bc06b54f488003748f1aa7f219.tar.gz
Paper-0a8c87372246f2bc06b54f488003748f1aa7f219.zip
Call LivingEntity#onItemPickup before mutation (#9948)
The existing EntityPickupItemEvent fixes patch moves the call to LivingEntity#onItemPickup for piglins after the respective EntityPickupItemEvent calls, which is correct. However the patch moved the call so far down the line that the existing logic already mutated the picked up item entity, leading to faulty state being passed to the onItemPickup method. To prevent logic in LivingEntity#onItemPickup to read from an ItemEntity that was already mutated, this commit moves the calls prior to the two respective mutations (either gold_nugget or rest). This was chosen above taking a copy of the original item and restoring state later on to avoid a full item stack clone.
-rw-r--r--patches/server/0859-EntityPickupItemEvent-fixes.patch16
1 files changed, 7 insertions, 9 deletions
diff --git a/patches/server/0859-EntityPickupItemEvent-fixes.patch b/patches/server/0859-EntityPickupItemEvent-fixes.patch
index d052f8e0a1..ac3383dced 100644
--- a/patches/server/0859-EntityPickupItemEvent-fixes.patch
+++ b/patches/server/0859-EntityPickupItemEvent-fixes.patch
@@ -25,10 +25,10 @@ index 1c42425b9211bea7cb189e967e566ad80fd278c2..6407ddef8442fce4f310ac4babf3e3de
}
diff --git a/src/main/java/net/minecraft/world/entity/monster/piglin/PiglinAi.java b/src/main/java/net/minecraft/world/entity/monster/piglin/PiglinAi.java
-index f0059bd69705ecc7964867b103c93e1df9985803..5c13e376dd079134da465044f1057bcce66973a3 100644
+index f0059bd69705ecc7964867b103c93e1df9985803..372d084609216d5437b92ee60810a9efbb0b6f31 100644
--- a/src/main/java/net/minecraft/world/entity/monster/piglin/PiglinAi.java
+++ b/src/main/java/net/minecraft/world/entity/monster/piglin/PiglinAi.java
-@@ -241,7 +241,10 @@ public class PiglinAi {
+@@ -241,11 +241,16 @@ public class PiglinAi {
ItemStack itemstack;
// CraftBukkit start
@@ -36,18 +36,16 @@ index f0059bd69705ecc7964867b103c93e1df9985803..5c13e376dd079134da465044f1057bcc
+ // Paper start - fix event firing twice
+ if (drop.getItem().is(Items.GOLD_NUGGET) /* && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(piglin, drop, 0, false).isCancelled() */) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(piglin, drop, 0, false).isCancelled()) return;
++ piglin.onItemPickup(drop); // Paper - moved from Piglin#pickUpItem - call prior to item entity modification
+ // Paper end
piglin.take(drop, drop.getItem().getCount());
itemstack = drop.getItem();
drop.discard();
-@@ -251,6 +254,7 @@ public class PiglinAi {
+ } else if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(piglin, drop, drop.getItem().getCount() - 1, false).isCancelled()) {
++ piglin.onItemPickup(drop); // Paper - moved from Piglin#pickUpItem - call prior to item entity modification
+ piglin.take(drop, 1);
+ itemstack = PiglinAi.removeOneItemFromItemEntity(drop);
} else {
- return;
- }
-+ piglin.onItemPickup(drop); // Paper - moved from Piglin#pickUpItem
- // CraftBukkit end
-
- if (PiglinAi.isLovedItem(itemstack, piglin)) { // CraftBukkit - Changes to allow for custom payment in bartering
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raider.java b/src/main/java/net/minecraft/world/entity/raid/Raider.java
index 5538f7a9024d8708b70de836aa78a4015656a828..cdbc925ef61b8b439415f0a89368227890bcecb2 100644
--- a/src/main/java/net/minecraft/world/entity/raid/Raider.java