geforkt von Mirrors/Paper
1718f61bf8
Doesn't compile yet. CraftBukkit Changes: 90d6905b Repackage NMS 69cf961d Repackage patches Spigot Changes: 79d53c28 Repackage NMS
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/world/entity/EntityExperienceOrb.java b/src/main/java/net/minecraft/world/entity/EntityExperienceOrb.java
|
|
index 1fd4bd03463a76e838d1aaa8e6f16f7a42f96fa7..dc257a7cafc4b728aa5c99ca332143bb05896d7e 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityExperienceOrb.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityExperienceOrb.java
|
|
@@ -264,10 +264,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/net/minecraft/world/item/enchantment/EnchantmentManager.java b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentManager.java
|
|
index d313b02f41e4f4a90676cbb37afce4e92dd4d664..72afbf8f537770540e90a2880ea81de137ea10f5 100644
|
|
--- a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentManager.java
|
|
+++ b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentManager.java
|
|
@@ -269,8 +269,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/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index cf9ae60db30ef09bb4c89935a42632e562b6d61e..f8780db8f376ee71a35ebe1c2ab84a6117d0d74e 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1180,8 +1180,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);
|
|
}
|
|
|