Hello guys! I'm making a mod that adds some weapons with abilitys to the game, however when using the ability I want to damage the sword by an x amount of it's durability, its there anyway a could do that?
To reduce the durability of an item, you would use ItemStack.damageItem(), for example:
event.getItemStack().damageItem(amount of damage, player, e -> e.sendBreakAnimation(EquipmentSlotType.MAINHAND);
The last parameter is used for creating the break animation when the item completely runs out of durability. You could for example check out the elytraFlightTick() method in the ElytraItem class to see an example of how vanilla uses the damageItem() method.
This works perfectly! thank you so much for your help, also is there some place where you could see all of this methods?
Well, the best place to look for methods is the vanilla source code. In your specific example, I knew that the Elytra has durability, so I looked in the ElytraItem class, and found what I was looking for - damageItem(). Otherwise I might have checked the ItemStack class, where the definition of damageItem() can be found. However, since the ItemStack class is more than 1000 lines of code it can be hard to sift through to find what you are looking for.
So if you want to find some functionality, but do not know the exact name of the method, look at classes where you would expect to find the functionality, and hopefully you will find what you are looking for.