From bc02501cc231add7f4d305215282579e5f5ce92c Mon Sep 17 00:00:00 2001 From: HexedHero <6012891+HexedHero@users.noreply.github.com> Date: Sun, 10 Apr 2022 06:26:32 +0100 Subject: [PATCH] Expand PlayerItemDamageEvent --- .../minecraft/world/item/ItemStack.java.patch | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch b/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch index bcce8abe2a..4225fdb684 100644 --- a/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch @@ -349,18 +349,19 @@ ItemStack itemstack = this.copy(); boolean flag = this.getUseDuration(user) <= 0; InteractionResult enuminteractionresult = this.getItem().use(world, user, hand); -@@ -490,27 +697,55 @@ +@@ -490,8 +697,32 @@ return this.isDamageableItem() && this.getDamageValue() >= this.getMaxDamage() - 1; } - public void hurtAndBreak(int amount, ServerLevel world, @Nullable ServerPlayer player, Consumer breakCallback) { + public void hurtAndBreak(int amount, ServerLevel world, @Nullable LivingEntity player, Consumer breakCallback) { // Paper - Add EntityDamageItemEvent ++ int originalDamage = amount; // Paper - Expand PlayerItemDamageEvent int j = this.processDurabilityChange(amount, world, player); + // CraftBukkit start + if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent -+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j); // Paper - Add EntityDamageItemEvent ++ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j, originalDamage); // Paper - Add EntityDamageItemEvent + event.getPlayer().getServer().getPluginManager().callEvent(event); - ++ + if (j != event.getDamage() || event.isCancelled()) { + event.getPlayer().updateInventory(); + } @@ -379,10 +380,10 @@ + // Paper end - Add EntityDamageItemEvent + } + // CraftBukkit end -+ + if (j != 0) { this.applyDamage(this.getDamageValue() + j, player, breakCallback); - } +@@ -499,18 +730,23 @@ } @@ -411,7 +412,7 @@ this.shrink(1); breakCallback.accept(item); -@@ -518,7 +753,7 @@ +@@ -518,7 +754,7 @@ } @@ -420,7 +421,7 @@ if (player instanceof ServerPlayer entityplayer) { int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer); -@@ -546,7 +781,7 @@ +@@ -546,7 +782,7 @@ entityplayer = null; } @@ -429,7 +430,7 @@ entity.onEquippedItemBroken(item, slot); }); } -@@ -580,11 +815,11 @@ +@@ -580,11 +816,11 @@ return this.getItem().getBarColor(this); } @@ -443,7 +444,7 @@ return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference); } -@@ -592,8 +827,8 @@ +@@ -592,8 +828,8 @@ Item item = this.getItem(); if (item.hurtEnemy(this, target, user)) { @@ -454,7 +455,7 @@ entityhuman.awardStat(Stats.ITEM_USED.get(item)); } -@@ -608,7 +843,7 @@ +@@ -608,7 +844,7 @@ this.getItem().postHurtEnemy(this, target, user); } @@ -463,7 +464,7 @@ Item item = this.getItem(); if (item.mineBlock(this, world, state, pos, miner)) { -@@ -617,11 +852,11 @@ +@@ -617,11 +853,11 @@ } @@ -477,7 +478,7 @@ return this.getItem().interactLivingEntity(this, user, entity, hand); } -@@ -736,7 +971,7 @@ +@@ -736,7 +972,7 @@ } @@ -486,7 +487,7 @@ player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount); this.getItem().onCraftedBy(this, world, player); } -@@ -770,6 +1005,12 @@ +@@ -770,6 +1006,12 @@ return this.getItem().useOnRelease(this); } @@ -499,7 +500,7 @@ @Nullable public T set(DataComponentType type, @Nullable T value) { return this.components.set(type, value); -@@ -803,8 +1044,27 @@ +@@ -803,8 +1045,27 @@ this.components.restorePatch(datacomponentpatch1); } else { this.getItem().verifyComponentsAfterLoad(this); @@ -527,7 +528,7 @@ public void applyComponents(DataComponentPatch changes) { this.components.applyPatch(changes); -@@ -858,7 +1118,7 @@ +@@ -858,7 +1119,7 @@ } private void addToTooltip(DataComponentType componentType, Item.TooltipContext context, Consumer textConsumer, TooltipFlag type) { @@ -536,7 +537,7 @@ if (t0 != null) { t0.addToTooltip(context, textConsumer, type); -@@ -866,7 +1126,7 @@ +@@ -866,7 +1127,7 @@ } @@ -545,7 +546,7 @@ boolean flag = this.getItem().shouldPrintOpWarning(this, player); if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) { -@@ -941,7 +1201,7 @@ +@@ -941,7 +1202,7 @@ } } @@ -554,7 +555,7 @@ ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY); if (itemattributemodifiers.showInTooltip()) { -@@ -966,7 +1226,7 @@ +@@ -966,7 +1227,7 @@ } } @@ -563,7 +564,7 @@ double d0 = modifier.amount(); boolean flag = false; -@@ -1091,6 +1351,14 @@ +@@ -1091,6 +1352,14 @@ EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer); } @@ -578,7 +579,7 @@ public Component getDisplayName() { MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName()); -@@ -1153,7 +1421,7 @@ +@@ -1153,7 +1422,7 @@ } public void consume(int amount, @Nullable LivingEntity entity) {