aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0280-ItemStack-repair-check-API.patch
blob: 0a9c5b65db5100ad3d15882589c373b56dd4ce46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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 42e4983051062f2fd3b595487cf8093440b41bba..057f4db9cb6b686ab941ec5d3e6ca23dcfbd845f 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -187,6 +187,16 @@ public interface UnsafeValues {
      */
     public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack);
 
+    /**
+     * 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);
+
     /**
      * Returns the server's protocol version.
      *
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index 569f67ee3f89d6af4fe1420cecc74811550b6507..78ea59c8f63b5a71ba092cf1783183bb5d0a3b79 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -898,5 +898,27 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
     public io.papermc.paper.inventory.ItemRarity getRarity() {
         return Bukkit.getUnsafe().getItemStackRarity(this);
     }
+
+    /**
+     * 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
 }