2021-06-11 14:02:28 +02:00
|
|
|
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
|
2024-05-11 23:48:37 +02:00
|
|
|
index 8635846c9f672e39f0929eec7bf83b22536ed284..51f1a09164d501de6d2561ed90175f2c24a668c1 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/UnsafeValues.java
|
|
|
|
+++ b/src/main/java/org/bukkit/UnsafeValues.java
|
2024-05-11 23:48:37 +02:00
|
|
|
@@ -185,5 +185,15 @@ public interface UnsafeValues {
|
2024-04-27 01:43:59 +02:00
|
|
|
* @return the server's protocol version
|
2021-06-11 14:02:28 +02:00
|
|
|
*/
|
2024-04-27 01:43:59 +02:00
|
|
|
int getProtocolVersion();
|
|
|
|
+
|
2021-06-11 14:02:28 +02:00
|
|
|
+ /**
|
|
|
|
+ * 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);
|
2024-04-27 01:43:59 +02:00
|
|
|
// Paper end
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
|
2024-06-14 14:11:52 +02:00
|
|
|
index e2f8a0d3a9dcab3fce2d71221751434abc9ab94f..057c87bc25b23f5fb3c34d0de781b7e125921439 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
|
|
|
|
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
|
2024-06-14 14:11:52 +02:00
|
|
|
@@ -919,5 +919,27 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
|
2021-06-11 14:02:28 +02:00
|
|
|
public io.papermc.paper.inventory.ItemRarity getRarity() {
|
2024-04-27 01:43:59 +02:00
|
|
|
return io.papermc.paper.inventory.ItemRarity.valueOf(this.getItemMeta().getRarity().name());
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 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
|
|
|
|
}
|