Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
899bc53b79
Upstream has released updates that appears 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: f47abd88 SPIGOT-6242: Fix some file line endings de96535b SPIGOT-6234: enum classes don't serialize properly when implementing ConfigurationSerializable CraftBukkit Changes: 4475707d SPIGOT-6244: /spawnpoint ignores angle 8b3b096d SPIGOT-6242: Fix some file line endings 4b33c749 SPIGOT-6186: Canceling a CreatureSpawnEvent results in a "Unable to summon entity due to duplicate UUIDs" error 2b3ca726 SPIGOT-6236: Vehicle passenger portal cooldown does not change
87 Zeilen
4.4 KiB
Diff
87 Zeilen
4.4 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.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EnchantmentManager.java b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
index ff56d7b045d7d93419a5f2f35df70b3644ac55b0..7b263594304a9b745f583fe7178ac16936cbd93b 100644
|
|
--- a/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
+++ b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
@@ -251,8 +251,8 @@ public class EnchantmentManager {
|
|
return getEnchantmentLevel(Enchantments.CHANNELING, itemstack) > 0;
|
|
}
|
|
|
|
- @Nullable
|
|
- public static Entry<EnumItemSlot, ItemStack> b(Enchantment enchantment, EntityLiving entityliving) {
|
|
+ public static @javax.annotation.Nonnull ItemStack getRandomEquippedItemWithEnchant(Enchantment enchantment, EntityLiving entityliving) { Entry<EnumItemSlot, ItemStack> entry = b(enchantment, entityliving); return entry != null ? entry.getValue() : ItemStack.NULL_ITEM; } // Paper - OBFHELPER
|
|
+ @Nullable public static Entry<EnumItemSlot, ItemStack> b(Enchantment enchantment, EntityLiving entityliving) {
|
|
return a(enchantment, entityliving, (itemstack) -> {
|
|
return true;
|
|
});
|
|
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
index 8354d18aa03d29202c82227a1891903a64c7921b..4df7df781d12e38885ecfbc89dd1d42d9de14248 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
@@ -249,10 +249,12 @@ public class EntityExperienceOrb extends Entity {
|
|
}
|
|
}
|
|
|
|
+ public final int durToXp(int i) { return b(i); } // Paper OBFHELPER
|
|
private int b(int i) {
|
|
return i / 2;
|
|
}
|
|
|
|
+ public final int xpToDur(int i) { return c(i); } // Paper OBFHELPER
|
|
private int c(int i) {
|
|
return i * 2;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 366912aa71ec8cd654977443786fa3cc44e0566a..88da51fd414f0107ef0bbe5eea423c14275d6bc9 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1098,8 +1098,37 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
return GameMode.getByValue(getHandle().playerInteractManager.getGameMode().getId());
|
|
}
|
|
|
|
+ // Paper start
|
|
@Override
|
|
- public void giveExp(int exp) {
|
|
+ public int applyMending(int amount) {
|
|
+ EntityPlayer handle = getHandle();
|
|
+ // Logic copied from EntityExperienceOrb and remapped to unobfuscated methods/properties
|
|
+ net.minecraft.server.ItemStack itemstack = net.minecraft.server.EnchantmentManager.getRandomEquippedItemWithEnchant(net.minecraft.server.Enchantments.MENDING, handle);
|
|
+ if (!itemstack.isEmpty() && itemstack.getItem().usesDurability()) {
|
|
+
|
|
+ net.minecraft.server.EntityExperienceOrb orb = net.minecraft.server.EntityTypes.EXPERIENCE_ORB.create(handle.world);
|
|
+ orb.value = amount;
|
|
+ orb.spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.CUSTOM;
|
|
+ orb.setPositionRaw(handle.locX(), handle.locY(), handle.locZ());
|
|
+
|
|
+ int i = Math.min(orb.xpToDur(amount), itemstack.getDamage());
|
|
+ org.bukkit.event.player.PlayerItemMendEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemMendEvent(handle, orb, itemstack, i);
|
|
+ i = event.getRepairAmount();
|
|
+ orb.dead = true;
|
|
+ if (!event.isCancelled()) {
|
|
+ amount -= orb.durToXp(i);
|
|
+ itemstack.setDamage(itemstack.getDamage() - i);
|
|
+ }
|
|
+ }
|
|
+ return amount;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void giveExp(int exp, boolean applyMending) {
|
|
+ if (applyMending) {
|
|
+ exp = this.applyMending(exp);
|
|
+ }
|
|
+ // Paper end
|
|
getHandle().giveExp(exp);
|
|
}
|
|
|