mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 07:39:16 +01:00
3496f2d7e4
Developers!: You will need to clean up your work/Minecraft/1.13.2 folder for this 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: b850a822 SPIGOT-4526: Add conversion time API for Zombie & subclasses CraftBukkit Changes:38cf676e
SPIGOT-4534: CreatureSpawnEvent not being called for CHUNK_GENb446cb5d
SPIGOT-4527: Fix sponges with waterlogged blocks6ec8ea5c
SPIGOT-4526: Add conversion time API for Zombie & subclassesc64fe508
Mappings Updatea3c2ec03
Fix missing ServerListPingEvent call for legacy pings Spigot Changes: 1dc156ce Rebuild patches 140f654d Mappings Update
88 lines
3.9 KiB
Diff
88 lines
3.9 KiB
Diff
From f4958d9d4612617fd65171cd018b29a9000af5fd 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 e1ea8da88..f1921e151 100644
|
|
--- a/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
+++ b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
|
@@ -223,6 +223,7 @@ public class EnchantmentManager {
|
|
return getEnchantmentLevel(Enchantments.CHANNELING, itemstack) > 0;
|
|
}
|
|
|
|
+ public static ItemStack getRandomEquippedItemWithEnchant(Enchantment enchantment, EntityLiving entityliving) { return b(enchantment, entityliving); } // Paper - OBFHELPER
|
|
public static ItemStack b(Enchantment enchantment, EntityLiving entityliving) {
|
|
List<ItemStack> list = enchantment.a(entityliving);// Paper - decompile fix
|
|
if (list.isEmpty()) {
|
|
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
index 4bcae2c21..09d85764b 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
@@ -246,10 +246,12 @@ public class EntityExperienceOrb extends Entity {
|
|
}
|
|
}
|
|
|
|
+ public int durToXp(int i) { return b(i); } // Paper OBFHELPER
|
|
private int b(int i) {
|
|
return i / 2;
|
|
}
|
|
|
|
+ public 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 8046a2a5f..45f7a4143 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1023,8 +1023,39 @@ 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 = new net.minecraft.server.EntityExperienceOrb(handle.world);
|
|
+ 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);
|
|
}
|
|
|
|
--
|
|
2.20.0
|
|
|