mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
d1a72eac31
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
89 lines
5.7 KiB
Diff
89 lines
5.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
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 7497471649bec04ab8b43dec06b31edd892a5cfb..ad1cb11245108b5cb187b686ed7e6bc769193b52 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;
|
|
@@ -681,8 +689,8 @@ public final class ItemStack implements DataComponentHolder {
|
|
if (j >= this.getMaxDamage()) {
|
|
Item item = this.getItem();
|
|
// CraftBukkit start - Check for item breaking
|
|
- if (this.count == 1) {
|
|
- org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent(player, this);
|
|
+ if (this.count == 1 && player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent(serverPlayer, this); // Paper - Add EntityDamageItemEvent
|
|
}
|
|
// CraftBukkit end
|
|
|
|
@@ -706,7 +714,7 @@ public final class ItemStack implements DataComponentHolder {
|
|
entityplayer = null;
|
|
}
|
|
|
|
- this.hurtAndBreak(amount, worldserver, entityplayer, (item) -> {
|
|
+ this.hurtAndBreak(amount, worldserver, entity, (item) -> { // Paper - Add EntityDamageItemEvent
|
|
entity.onEquippedItemBroken(item, slot);
|
|
});
|
|
}
|
|
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
|