Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
3b9db2b194
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: bb4e97c6 Add support for Java 23 bc6874dd Bump asm to 9.7.1 50e8a00b PR-1064: Add specific getTopInventory methods for InventoryView derivatives 758b0a0f SPIGOT-7911: Fix Location#isWorldLoaded() for re-loaded worlds 133a64a7 Improve Registry#getOrThrow messages be0f5957 PR-1058: Add tests for Minecraft registry <-> Bukkit fields d1b31df2 PR-1062: Clarify BeaconView documentation 3fab4384 PR-1060: Cache Material to BlockType and ItemType conversion 967a7301 SPIGOT-7906: Increase YAML nesting limit to 100 6ecf033d SPIGOT-7899: Smithing recipes don't require inputs CraftBukkit Changes: 0a7bd6c81 PR-1493: Improve reroute performance and add some tests 54941524c Add support for Java 23 f4d957fff SPIGOT-7915: Fix World#getKeepSpawnInMemory() using Spawn Radius rather than Spawn Chunk Radius ded183674 Fix HIDE_ENCHANTS flag in items without enchantments 308785a0a Bump asm to 9.7.1 and re-add ClassReader to ClassWriter 72ce823cd PR-1487: Add specific getTopInventory methods for InventoryView derivatives 11a5e840c SPIGOT-7907, PR-1484: Improve merchant recipe item matching behavior to more closely align with older versions 45b66f7e4 SPIGOT-7909: Always set HIDE_ENCHANTS flag to item if flag is set 963459791 Increase outdated build delay fc5b2d75f SPIGOT-7910: Fix launching breeze wind charge from API and improve dispenser launch API c7d6428f2 SPIGOT-7856, PR-1483: End platform not dropping items after replacing blocks 2a5572b52 SPIGOT-7780, PR-1482: Cannot edit chunks during unload event 527041ab5 SPIGOT-7902, PR-1477: Fix CraftMetaPotion#hasCustomEffects() does not check if customEffects (List) is empty 5529a1769 Implement base methods for tags 30fbdbaaf Improve Registry#getOrThrow messages 6b71a7322 PR-1475: Add tests for Minecraft registry <-> Bukkit fields 5f24c255c SPIGOT-7908: Mark junit-platform-suite-engine as test scope e4c92ef65 PR-1473: Change tests to use suites, to run tests in different environments and feature flags d25e1e722 PR-1481: Fix BeaconView#set[X]Effect(null) d69a05362 PR-1480: Fix PerMaterialTest#isEdible test running for legacy materials bb3284a89 PR-1479: Use custom #isBlock method in legacy init instead of the one in Material, since it relies on legacy being init 98c57cbbe SPIGOT-7904: Fix NPE for PlayerItemBreakEvent f35bae9ec Fix missing hasJukeboxPlayable 8a6f8b6d8 SPIGOT-7881: CTRL+Pick Block saves position data into item 7913b3be7 SPIGOT-7899: Smithing recipes don't require inputs
90 Zeilen
5.7 KiB
Diff
90 Zeilen
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 d1eac70fbfe2d863d3a342ed0e83223c65c36c03..a98d76c90cd855e723e7a8d810eee88a882d8b5c 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 && player != null) {
|
|
- org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent(player, this);
|
|
+ if (this.count == 1 && player != null && 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
|