mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
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.
This commit is contained in:
parent
95c2b76467
commit
8b711f86a3
1 changed files with 5 additions and 7 deletions
|
@ -36,18 +36,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ // 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();
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/raid/Raider.java
|
||||
|
|
Loading…
Reference in a new issue