mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-27 12:35:12 +01:00
Added the ability to check if a tool has the required durability.
This commit is contained in:
parent
4df7618f96
commit
c9f4876f29
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user