mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
34 lines
2.2 KiB
Diff
34 lines
2.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Bjarne Koll <lynxplay101@gmail.com>
|
|
Date: Fri, 12 Jul 2024 19:09:44 +0200
|
|
Subject: [PATCH] Correctly call PlayerItemBreakEvent
|
|
|
|
The minecraft 1.21 update changed the invocation order in
|
|
ItemStack#hurtAndBreak, now first shrinking the itemstack to a count of
|
|
zero and then invoking the break callback.
|
|
|
|
This leads to spigots logic no longer firing at all. This patch now
|
|
correctly executes on count of zero and temporarily bumps the count to
|
|
one before passing it to event handlers to maintain compatibility with
|
|
the event contracts.
|
|
|
|
This fix was chosen over invoking the callback prior to shrinking the
|
|
stack to not disrupt potential new vanilla changes that might depend on
|
|
this behaviour.
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
index 0f2b3c5ca88478a541bf9e61ae61cc99a7d08836..2c312c0b741fb96a008881e9e01fa660a1fb63ab 100644
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
@@ -731,8 +731,10 @@ public final class ItemStack implements DataComponentHolder {
|
|
|
|
this.hurtAndBreak(amount, worldserver, entity, (item) -> { // Paper - Add EntityDamageItemEvent
|
|
// CraftBukkit start - Check for item breaking
|
|
- if (this.count == 1 && entity instanceof net.minecraft.world.entity.player.Player) {
|
|
+ if (this.count == 0 && entity instanceof net.minecraft.world.entity.player.Player) { // Paper - correctly call item break event - run if count reached 0
|
|
+ this.setCount(1); // Paper - correctly call item break event - grow to count 1
|
|
org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((net.minecraft.world.entity.player.Player) entity, this);
|
|
+ this.setCount(0); // Paper - correctly call item break event - reset to count 0
|
|
}
|
|
// CraftBukkit end
|
|
if (slot != null) entity.onEquippedItemBroken(item, slot); // Paper - itemstack damage API - do not process entity related callbacks when damaging from API
|