Added the ability to check if a tool has the required durability.

This commit is contained in:
Brianna 2020-10-29 13:31:12 -05:00
parent 4df7618f96
commit c9f4876f29

View File

@ -134,6 +134,21 @@ public class ItemUtils {
return item;
}
public static boolean hasEnoughDurability(ItemStack tool, int requiredAmount) {
if (tool.getType().getMaxDurability() <= 1)
return true;
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
if (!tool.hasItemMeta() || !(tool.getItemMeta() instanceof Damageable))
return true;
Damageable damageable = (Damageable) tool.getItemMeta();
int durabilityRemaining = tool.getType().getMaxDurability() - damageable.getDamage();
return durabilityRemaining > requiredAmount;
} else {
return tool.getDurability() + requiredAmount <= tool.getType().getMaxDurability();
}
}
static Class cb_ItemStack = NMSUtils.getCraftClass("inventory.CraftItemStack");
static Class mc_ItemStack = NMSUtils.getNMSClass("ItemStack");
static Class mc_NBTTagCompound = NMSUtils.getNMSClass("NBTTagCompound");