geforkt von Mirrors/Paper
4e994669d3
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: 6b3c598b PR-814: Add a method to send multiple equipment changes 181a984b Update Maven shade version to align with CraftBukkit a5a36e32 Revert "Update Maven shade version to align with CraftBukkit" 7a8f4a42 Update Maven shade version to align with CraftBukkit 58327201 Add support for Java 20 CraftBukkit Changes: b56426c7a PR-1142: Calculate explosion damage separately for each affected EntityComplexPart fbe3410af PR-1140: Add a method to send multiple equipment changes 8434e3633 Add support for Java 20 c998a1d23 Increase outdated build delay 4a929b5d6 SPIGOT-7267: Fix EntityType#getTranslationKey() and add unit test 086d8dc8a SPIGOT-7268: CraftMetaPotion reads ShowParticles and ShowIcon properties incorrectly 8ba5e399e SPIGOT-7262: Improve visibility API Spigot Changes: a2190e30 Rebuild patches
59 Zeilen
2.8 KiB
Diff
59 Zeilen
2.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Wed, 20 Dec 2017 17:36:49 -0500
|
|
Subject: [PATCH] Ability to apply mending to XP API
|
|
|
|
This allows plugins that give players the ability to apply the experience
|
|
points to the Item Mending formula, which will repair an item instead
|
|
of giving the player experience points.
|
|
|
|
Both an API To standalone mend, and apply mending logic to .giveExp has been added.
|
|
|
|
== AT ==
|
|
public net.minecraft.world.entity.ExperienceOrb durabilityToXp(I)I
|
|
public net.minecraft.world.entity.ExperienceOrb xpToDurability(I)I
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index dfc5a445744520388bd09cf4a68a232885c6e2c9..43fed86150b15294ed4aeb1a6139891456754c97 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1470,7 +1470,37 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
|
|
@Override
|
|
- public void giveExp(int exp) {
|
|
+ // Paper start
|
|
+ public int applyMending(int amount) {
|
|
+ ServerPlayer handle = this.getHandle();
|
|
+ // Logic copied from EntityExperienceOrb and remapped to unobfuscated methods/properties
|
|
+ final var stackEntry = net.minecraft.world.item.enchantment.EnchantmentHelper
|
|
+ .getRandomItemWith(net.minecraft.world.item.enchantment.Enchantments.MENDING, handle);
|
|
+ final net.minecraft.world.item.ItemStack itemstack = stackEntry != null ? stackEntry.getValue() : net.minecraft.world.item.ItemStack.EMPTY;
|
|
+ if (!itemstack.isEmpty() && itemstack.getItem().canBeDepleted()) {
|
|
+ net.minecraft.world.entity.ExperienceOrb orb = net.minecraft.world.entity.EntityType.EXPERIENCE_ORB.create(handle.level);
|
|
+ orb.value = amount;
|
|
+ orb.spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.CUSTOM;
|
|
+ orb.setPosRaw(handle.getX(), handle.getY(), handle.getZ());
|
|
+
|
|
+ int i = Math.min(orb.xpToDurability(amount), itemstack.getDamageValue());
|
|
+ org.bukkit.event.player.PlayerItemMendEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemMendEvent(handle, orb, itemstack, stackEntry.getKey(), i);
|
|
+ i = event.getRepairAmount();
|
|
+ orb.discard();
|
|
+ if (!event.isCancelled()) {
|
|
+ amount -= orb.durabilityToXp(i);
|
|
+ itemstack.setDamageValue(itemstack.getDamageValue() - i);
|
|
+ }
|
|
+ }
|
|
+ return amount;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void giveExp(int exp, boolean applyMending) {
|
|
+ if (applyMending) {
|
|
+ exp = this.applyMending(exp);
|
|
+ }
|
|
+ // Paper end
|
|
this.getHandle().giveExperiencePoints(exp);
|
|
}
|
|
|