diff options
author | Spottedleaf <[email protected]> | 2024-07-17 10:24:53 -0700 |
---|---|---|
committer | Spottedleaf <[email protected]> | 2024-07-17 10:28:32 -0700 |
commit | 00b949f1bbbf444e2b5e7b8de7c9b14fbd2133c6 (patch) | |
tree | 82639515bc5e9ae00c1e639e72137ed51e1ac688 /patches/server/0578-Add-EntityDamageItemEvent.patch | |
parent | 967f98aa81da851740aeb429778e46159fd188df (diff) | |
download | Paper-00b949f1bbbf444e2b5e7b8de7c9b14fbd2133c6.tar.gz Paper-00b949f1bbbf444e2b5e7b8de7c9b14fbd2133c6.zip |
Remove Moonrise utils to MCUtils, remove duplicated/unused utils
Diffstat (limited to 'patches/server/0578-Add-EntityDamageItemEvent.patch')
-rw-r--r-- | patches/server/0578-Add-EntityDamageItemEvent.patch | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/patches/server/0578-Add-EntityDamageItemEvent.patch b/patches/server/0578-Add-EntityDamageItemEvent.patch new file mode 100644 index 0000000000..d9c3b86a2a --- /dev/null +++ b/patches/server/0578-Add-EntityDamageItemEvent.patch @@ -0,0 +1,78 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic <[email protected]> +Date: Tue, 22 Dec 2020 13:52:48 -0800 +Subject: [PATCH] Add EntityDamageItemEvent + + +diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java +index 7f7445a2b68fd2e6e5fcd509d950a0f8d680c1fe..ebc5f2e8d59da4bec25ff156ec95fe49366be59c 100644 +--- a/src/main/java/net/minecraft/world/item/ItemStack.java ++++ b/src/main/java/net/minecraft/world/item/ItemStack.java +@@ -646,14 +646,14 @@ public final class ItemStack implements DataComponentHolder { + return (Integer) this.getOrDefault(DataComponents.MAX_DAMAGE, 0); + } + +- public void hurtAndBreak(int amount, ServerLevel world, @Nullable ServerPlayer player, Consumer<Item> breakCallback) { ++ public void hurtAndBreak(int amount, ServerLevel world, @Nullable LivingEntity player, Consumer<Item> breakCallback) { // Paper - Add EntityDamageItemEvent + if (this.isDamageableItem()) { + if (player == null || !player.hasInfiniteMaterials()) { + if (amount > 0) { + amount = EnchantmentHelper.processDurabilityChange(world, this, amount); + // CraftBukkit start +- if (player != null) { +- PlayerItemDamageEvent event = new PlayerItemDamageEvent(player.getBukkitEntity(), CraftItemStack.asCraftMirror(this), amount); ++ if (player instanceof ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent ++ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), amount); // Paper - Add EntityDamageItemEvent + event.getPlayer().getServer().getPluginManager().callEvent(event); + + if (amount != event.getDamage() || event.isCancelled()) { +@@ -664,6 +664,14 @@ public final class ItemStack implements DataComponentHolder { + } + + amount = event.getDamage(); ++ // Paper start - Add EntityDamageItemEvent ++ } else if (player != null) { ++ io.papermc.paper.event.entity.EntityDamageItemEvent event = new io.papermc.paper.event.entity.EntityDamageItemEvent(player.getBukkitLivingEntity(), CraftItemStack.asCraftMirror(this), amount); ++ if (!event.callEvent()) { ++ return; ++ } ++ amount = event.getDamage(); ++ // Paper end - Add EntityDamageItemEvent + } + // CraftBukkit end + if (amount <= 0) { +@@ -671,8 +679,8 @@ public final class ItemStack implements DataComponentHolder { + } + } + +- if (player != null && amount != 0) { +- CriteriaTriggers.ITEM_DURABILITY_CHANGED.trigger(player, this, this.getDamageValue() + amount); ++ if (player instanceof ServerPlayer serverPlayer && amount != 0) { // Paper - Add EntityDamageItemEvent ++ CriteriaTriggers.ITEM_DURABILITY_CHANGED.trigger(serverPlayer, this, this.getDamageValue() + amount); // Paper - Add EntityDamageItemEvent + } + + int j = this.getDamageValue() + amount; +@@ -701,7 +709,7 @@ public final class ItemStack implements DataComponentHolder { + entityplayer = null; + } + +- this.hurtAndBreak(amount, worldserver, entityplayer, (item) -> { ++ 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) { + org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((net.minecraft.world.entity.player.Player) entity, this); +diff --git a/src/main/java/net/minecraft/world/item/enchantment/effects/DamageItem.java b/src/main/java/net/minecraft/world/item/enchantment/effects/DamageItem.java +index 70796eef426eece0bc93a173f54e90645377b502..82ac989ca836e3beef7c3773db0183a7e51780e0 100644 +--- a/src/main/java/net/minecraft/world/item/enchantment/effects/DamageItem.java ++++ b/src/main/java/net/minecraft/world/item/enchantment/effects/DamageItem.java +@@ -16,8 +16,8 @@ public record DamageItem(LevelBasedValue amount) implements EnchantmentEntityEff + + @Override + public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity user, Vec3 pos) { +- ServerPlayer serverPlayer2 = context.owner() instanceof ServerPlayer serverPlayer ? serverPlayer : null; +- context.itemStack().hurtAndBreak((int)this.amount.calculate(level), world, serverPlayer2, context.onBreak()); ++ // ServerPlayer serverPlayer2 = context.owner() instanceof ServerPlayer serverPlayer ? serverPlayer : null; // Paper - always pass in entity ++ context.itemStack().hurtAndBreak((int)this.amount.calculate(level), world, context.owner(), context.onBreak()); // Paper - always pass in entity + } + + @Override |