aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0279-ItemStack-repair-check-API.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/api/0279-ItemStack-repair-check-API.patch')
-rw-r--r--patches/api/0279-ItemStack-repair-check-API.patch58
1 files changed, 58 insertions, 0 deletions
diff --git a/patches/api/0279-ItemStack-repair-check-API.patch b/patches/api/0279-ItemStack-repair-check-API.patch
new file mode 100644
index 0000000000..5949d4de6b
--- /dev/null
+++ b/patches/api/0279-ItemStack-repair-check-API.patch
@@ -0,0 +1,58 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jake Potrebic <[email protected]>
+Date: Sat, 15 May 2021 22:10:50 -0700
+Subject: [PATCH] ItemStack repair check API
+
+
+diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
+index 5f2d521a54d03a2270a1812146f954dc16c9d728..0a8a9e6fbead467737530ce6c84560dcbb803282 100644
+--- a/src/main/java/org/bukkit/UnsafeValues.java
++++ b/src/main/java/org/bukkit/UnsafeValues.java
+@@ -177,5 +177,15 @@ public interface UnsafeValues {
+ * @return the server's protocol version
+ */
+ int getProtocolVersion();
++
++ /**
++ * Checks if an itemstack can be repaired with another itemstack.
++ * Returns false if either argument's type is not an item ({@link Material#isItem()}).
++ *
++ * @param itemToBeRepaired the itemstack to be repaired
++ * @param repairMaterial the repair material
++ * @return true if valid repair, false if not
++ */
++ public boolean isValidRepairItemStack(@org.jetbrains.annotations.NotNull ItemStack itemToBeRepaired, @org.jetbrains.annotations.NotNull ItemStack repairMaterial);
+ // Paper end
+ }
+diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
+index a92421bbf0ee40ecbe4f272459c6a918dc45344c..04ff6579282708c48edee419381c698707fe0a3b 100644
+--- a/src/main/java/org/bukkit/inventory/ItemStack.java
++++ b/src/main/java/org/bukkit/inventory/ItemStack.java
+@@ -903,5 +903,27 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
+ public io.papermc.paper.inventory.ItemRarity getRarity() {
+ return io.papermc.paper.inventory.ItemRarity.valueOf(this.getItemMeta().getRarity().name());
+ }
++
++ /**
++ * Checks if an itemstack can repair this itemstack.
++ * Returns false if {@code this} or {@code repairMaterial}'s type is not an item ({@link Material#isItem()}).
++ *
++ * @param repairMaterial the repair material
++ * @return true if it is repairable by, false if not
++ */
++ public boolean isRepairableBy(@NotNull ItemStack repairMaterial) {
++ return Bukkit.getUnsafe().isValidRepairItemStack(this, repairMaterial);
++ }
++
++ /**
++ * Checks if this itemstack can repair another.
++ * Returns false if {@code this} or {@code toBeRepaired}'s type is not an item ({@link Material#isItem()}).
++ *
++ * @param toBeRepaired the itemstack to be repaired
++ * @return true if it can repair, false if not
++ */
++ public boolean canRepair(@NotNull ItemStack toBeRepaired) {
++ return Bukkit.getUnsafe().isValidRepairItemStack(toBeRepaired, this);
++ }
+ // Paper end
+ }