2018-09-29 01:31:59 +02:00
|
|
|
From 7b29c313c8795d2700da25e279a9377e57a4fe86 Mon Sep 17 00:00:00 2001
|
2017-12-20 23:50:26 +01:00
|
|
|
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
|
2018-09-01 00:56:57 +02:00
|
|
|
index fd6df39f17..f03aef2fed 100644
|
2017-12-20 23:50:26 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
2018-09-01 00:56:57 +02:00
|
|
|
@@ -223,6 +223,7 @@ public class EnchantmentManager {
|
2018-07-18 06:52:33 +02:00
|
|
|
return getEnchantmentLevel(Enchantments.F, itemstack) > 0;
|
2017-12-20 23:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+ public static ItemStack getRandomEquippedItemWithEnchant(Enchantment enchantment, EntityLiving entityliving) { return b(enchantment, entityliving); } // Paper - OBFHELPER
|
|
|
|
public static ItemStack b(Enchantment enchantment, EntityLiving entityliving) {
|
2018-09-01 00:56:57 +02:00
|
|
|
List<ItemStack> list = enchantment.a(entityliving);// Paper - decompile fix
|
|
|
|
if (list.isEmpty()) {
|
2017-12-20 23:50:26 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Enchantments.java b/src/main/java/net/minecraft/server/Enchantments.java
|
2018-09-01 00:56:57 +02:00
|
|
|
index 8cfb38b826..44b2d428b3 100644
|
2017-12-20 23:50:26 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/Enchantments.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Enchantments.java
|
2018-09-01 00:56:57 +02:00
|
|
|
@@ -35,7 +35,7 @@ public class Enchantments {
|
2018-07-18 06:52:33 +02:00
|
|
|
public static final Enchantment D = a("impaling");
|
|
|
|
public static final Enchantment E = a("riptide");
|
|
|
|
public static final Enchantment F = a("channeling");
|
|
|
|
- public static final Enchantment G = a("mending");
|
|
|
|
+ public static final Enchantment G = a("mending");public static final Enchantment MENDING = G; // Paper - OBFHELPER
|
|
|
|
public static final Enchantment H = a("vanishing_curse");
|
2017-12-20 23:50:26 +01:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
2018-08-26 20:11:49 +02:00
|
|
|
index dcef63bb1f..53cfc10017 100644
|
2017-12-20 23:50:26 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
2018-07-18 06:52:33 +02:00
|
|
|
@@ -246,10 +246,12 @@ public class EntityExperienceOrb extends Entity {
|
2017-12-20 23:50:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 06:52:33 +02:00
|
|
|
+ public int durToXp(int i) { return b(i); } // Paper OBFHELPER
|
|
|
|
private int b(int i) {
|
2017-12-20 23:50:26 +01:00
|
|
|
return i / 2;
|
|
|
|
}
|
|
|
|
|
2018-07-18 06:52:33 +02:00
|
|
|
+ public int xpToDur(int i) { return c(i); } // Paper OBFHELPER
|
|
|
|
private int c(int i) {
|
2017-12-20 23:50:26 +01:00
|
|
|
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
|
2018-09-29 01:31:59 +02:00
|
|
|
index 0d76a42997..1c40f17ce9 100644
|
2017-12-20 23:50:26 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2018-09-01 12:09:13 +02:00
|
|
|
@@ -1023,8 +1023,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2017-12-20 23:50:26 +01:00
|
|
|
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
|
2018-07-19 06:42:43 +02:00
|
|
|
+ net.minecraft.server.ItemStack itemstack = net.minecraft.server.EnchantmentManager.getRandomEquippedItemWithEnchant(net.minecraft.server.Enchantments.MENDING, handle);
|
|
|
|
+ if (!itemstack.isEmpty() && itemstack.getItem().usesDurability()) {
|
2017-12-20 23:50:26 +01:00
|
|
|
+
|
2018-07-19 06:42:43 +02:00
|
|
|
+ net.minecraft.server.EntityExperienceOrb orb = new net.minecraft.server.EntityExperienceOrb(handle.world);
|
2017-12-20 23:50:26 +01:00
|
|
|
+ orb.value = amount;
|
|
|
|
+ orb.spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.CUSTOM;
|
|
|
|
+ orb.locX = handle.locX;
|
|
|
|
+ orb.locY = handle.locY;
|
|
|
|
+ orb.locZ = 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2018-09-29 01:31:59 +02:00
|
|
|
2.19.0
|
2017-12-20 23:50:26 +01:00
|
|
|
|