Minecraft – How to lower durability of an item

minecraft-commandsminecraft-java-edition

I'm trying to make a jetpack with a battery using Vanilla Minecraft commands. The more you use it, the more the battery depletes. So far, I have the 'battery' part working and the jetpack itself, but I cannot figure out how to lower the durability of an item every time you use the jetpack.

I've used the carrot on a stick as the jetpack, so when I right click and hold it levitates me up slightly, and I got a chest plate as the battery (Because it has durability). I've also made it where the jetpack only works if you have the battery, so if the durability of the chest plate runs out, then it won't work anymore. My only issue is that I can't figure out how to lower the durability of the chest-plate (acting as the battery) when I use the jetpack.

Best Answer

Unfortunately, Minecraft currently dosent have a way to dynamically edit nbt data. (I.e, lower a durability value by 1). The only way do do this directly would be to have 2 command blocks for every durability value, and when you want it to drop, test for a durability and set it to the next value down (set the durability of chestplate with damage 4 to damage 3, and ect...). Another alternative you could look into is damaging the player. If this chestplate is being worn by the player, then dealing a small amount may lower thr durability by one.