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
|
2021-12-22 23:56:37 +01:00
|
|
|
index 62e40c2e5f0da64a40772ae1445c679fd1c7c457..e0043bb2890862d9227f5faf15a3e4993dfc59ca 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
|
2021-12-22 23:56:37 +01:00
|
|
|
@@ -156,6 +156,16 @@ public interface UnsafeValues {
|
2021-06-11 14:02:28 +02:00
|
|
|
*/
|
|
|
|
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
|
2021-08-14 06:11:12 +02:00
|
|
|
index f46aeb59a5a1bde4011cd1d933afcc19c7d1b3bd..86bd9f14de5c1ff3d797955be1af56e5efcac884 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
|
2021-08-14 06:11:12 +02:00
|
|
|
@@ -887,5 +887,27 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
|
2021-06-11 14:02:28 +02:00
|
|
|
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
|
|
|
|
}
|