1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-02-17 10:41:41 +01:00

ItemStack repair check API

This commit is contained in:
Jake Potrebic 2021-05-15 22:10:50 -07:00
parent d30a14d638
commit fce24f3b52
2 changed files with 32 additions and 0 deletions
paper-api/src/main/java/org/bukkit

View file

@ -187,5 +187,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
}

View file

@ -1006,5 +1006,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
}