geforkt von Mirrors/Paper
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.
Dieser Commit ist enthalten in:
Ursprung
21e410d42e
Commit
c3791a5225
51
Spigot-API-Patches/Ability-to-apply-mending-to-XP-API.patch
Normale Datei
51
Spigot-API-Patches/Ability-to-apply-mending-to-XP-API.patch
Normale Datei
@ -0,0 +1,51 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Wed, 20 Dec 2017 17:38:07 -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/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
|
||||
index 23cc8b5e..a882323d 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Player.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Player.java
|
||||
@@ -0,0 +0,0 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
|
||||
*/
|
||||
public void resetPlayerWeather();
|
||||
|
||||
+ // Paper start
|
||||
+ /**
|
||||
+ * Gives the player the amount of experience specified.
|
||||
+ *
|
||||
+ * @param amount Exp amount to give
|
||||
+ */
|
||||
+ public default void giveExp(int amount) {
|
||||
+ giveExp(amount, false);
|
||||
+ }
|
||||
/**
|
||||
* Gives the player the amount of experience specified.
|
||||
*
|
||||
* @param amount Exp amount to give
|
||||
+ * @param applyMending Mend players items with mending, with same behavior as picking up orbs. calls {@link #applyMending(int)}
|
||||
*/
|
||||
- public void giveExp(int amount);
|
||||
+ public void giveExp(int amount, boolean applyMending);
|
||||
+
|
||||
+ /**
|
||||
+ * Applies the mending effect to any items just as picking up an orb would.
|
||||
+ *
|
||||
+ * Can also be called with {@link #giveExp(int, boolean)} by passing true to applyMending
|
||||
+ *
|
||||
+ * @param amount
|
||||
+ * @return
|
||||
+ */
|
||||
+ public int applyMending(int amount);
|
||||
+ // Paper end
|
||||
|
||||
/**
|
||||
* Gives the player the amount of experience levels specified. Levels can
|
||||
--
|
125
Spigot-Server-Patches/Ability-to-apply-mending-to-XP-API.patch
Normale Datei
125
Spigot-Server-Patches/Ability-to-apply-mending-to-XP-API.patch
Normale Datei
@ -0,0 +1,125 @@
|
||||
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 98300d0a2..f714dc326 100644
|
||||
--- a/src/main/java/net/minecraft/server/EnchantmentManager.java
|
||||
+++ b/src/main/java/net/minecraft/server/EnchantmentManager.java
|
||||
@@ -0,0 +0,0 @@ public class EnchantmentManager {
|
||||
return getEnchantmentLevel(Enchantments.D, 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 list = enchantment.a(entityliving);
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/Enchantments.java b/src/main/java/net/minecraft/server/Enchantments.java
|
||||
index 35e87eb1c..74a6a4f60 100644
|
||||
--- a/src/main/java/net/minecraft/server/Enchantments.java
|
||||
+++ b/src/main/java/net/minecraft/server/Enchantments.java
|
||||
@@ -0,0 +0,0 @@ public class Enchantments {
|
||||
public static final Enchantment ARROW_INFINITE = a("infinity");
|
||||
public static final Enchantment LUCK = a("luck_of_the_sea");
|
||||
public static final Enchantment LURE = a("lure");
|
||||
- public static final Enchantment C = a("mending");
|
||||
+ public static final Enchantment C = a("mending"); public static final Enchantment MENDING = C; // Paper - OBFHELPER
|
||||
public static final Enchantment D = a("vanishing_curse");
|
||||
|
||||
@Nullable
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
||||
index ff5cc74ba..1c59fd966 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
||||
@@ -0,0 +0,0 @@ public class EntityExperienceOrb extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
+ public int durToXp(int i) { return c(i); } // Paper OBFHELPER
|
||||
private int c(int i) {
|
||||
return i / 2;
|
||||
}
|
||||
|
||||
+ public int xpToDur(int i) { return d(i); } // Paper OBFHELPER
|
||||
private int d(int i) {
|
||||
return i * 2;
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
|
||||
index 52cb34abd..45c8e4b1e 100644
|
||||
--- a/src/main/java/net/minecraft/server/ItemStack.java
|
||||
+++ b/src/main/java/net/minecraft/server/ItemStack.java
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack {
|
||||
private Item item;
|
||||
private NBTTagCompound tag;
|
||||
private boolean g;
|
||||
- private int damage;
|
||||
+ private int damage; public void setDamage(int i) { this.damage = 0; } // Paper - OBFHELPER
|
||||
private EntityItemFrame i;
|
||||
private Block j;
|
||||
private boolean k;
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack {
|
||||
return this.getItem().k();
|
||||
}
|
||||
|
||||
+ public boolean hasDamage() { return h(); } // Paper OBFHELPER
|
||||
public boolean h() {
|
||||
return this.f() && this.damage > 0;
|
||||
}
|
||||
|
||||
+ public int getDamage() { return i(); } // Paper OBFHELPER
|
||||
public int i() {
|
||||
return this.damage;
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
index eeab46333..5ed998a17 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
+ ItemStack itemstack = EnchantmentManager.getRandomEquippedItemWithEnchant(Enchantments.MENDING, handle);
|
||||
+ if (!itemstack.isEmpty() && itemstack.hasDamage()) {
|
||||
+
|
||||
+ EntityExperienceOrb orb = new 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);
|
||||
}
|
||||
|
||||
--
|
@ -62,6 +62,8 @@ import DataConverterMaterialId
|
||||
import DataInspectorBlockEntity
|
||||
import DataPalette
|
||||
import DefinedStructure
|
||||
import EnchantmentManager
|
||||
import Enchantments
|
||||
import EntityLlama
|
||||
import EntitySquid
|
||||
import EntityTypes
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren