I have a tool I want to give players but they can only use when its at full durability, I already know how to use the selector damage:0 and set the damage to something, but I would like to refill the item over time, kinda like a cool down timer for the item, how would I go about doing that?

oh also if possible I would like it to work from anywhere in their inventory,

I was thinking mending but it gives it a nasty glow, and wouldn't work if they had any other mending stuff on or if its not selected

replace item needs a defined slot, as I want this item to regenerate passively without having to hold it in main slot (cuz it would be useless if they constantly had to hold it) it wouldn't work,

I thought about data modify or data merge, but i'm too dumb to figure that one out

edit: It could even be a new item that takes its place, because its not really a dynamic item, you shouldn't need enchant or rename it, here is the give command for the full item

/give @s minecraft:carrot_on_a_stick{CustomModelData:1,display:{Name:"{\"text\":\"Killer Queen\",\"italic\":\"false\"}"}}

the only problem with clearing the item and giving it again with increasing durability is that the item may jump slots if you have any other slots empty, which would kind of break the illusion, though if it comes to that then I will

1 Answer 1


You cannot directly edit player NBT data. Something like in your case used to be possible by abusing this bug, but that was fixed. This means that you will now need to use /replaceitem. In theory /loot should also be able to be used to dynamically create items for various targets, including a specific slot in a player inventory, but this currently does not work due to this bug. That means that you will have to handle every possible slot and every possible damage value manually. Therefore you need 925 commands (instead of the 3 it would have taken with the fixed bug).

The principle is pretty easy: You can check the item's slot in player NBT and execute a /replaceitem command based on that:

/replaceitem entity @s[nbt={Inventory:[{Slot:0b,id:"minecraft:carrot_on_a_stick",tag:{…}}]}] hotbar.0 carrot_on_a_stick{…}
/replaceitem entity @s[nbt={Inventory:[{Slot:1b,id:"minecraft:carrot_on_a_stick",tag:{…}}]}] hotbar.1 carrot_on_a_stick{…}
/replaceitem entity @s[nbt={Inventory:[{Slot:8b,id:"minecraft:carrot_on_a_stick",tag:{…}}]}] hotbar.8 carrot_on_a_stick{…}
/replaceitem entity @s[nbt={Inventory:[{Slot:9b,id:"minecraft:carrot_on_a_stick",tag:{…}}]}] inventory.0 carrot_on_a_stick{…}
/replaceitem entity @s[nbt={Inventory:[{Slot:35b,id:"minecraft:carrot_on_a_stick",tag:{…}}]}] inventory.26 carrot_on_a_stick{…}
/replaceitem entity @s[nbt={Inventory:[{Slot:-106b,id:"minecraft:carrot_on_a_stick",tag:{…}}]}] weapon.offhand carrot_on_a_stick{…}

Replace in the selector with the old data and in the to-be-given item with the new data. That includes the old and the new durability, ranging from 25 to 1 (it breaks at 0).

  • ouch, well hopefully they fix that bug soon, I think i'll just have to keep it to /clear and /give, as I plan to turn this into a datapack I would like to keep the command count down for ease of editing and use, thank you anyway! I'll mark this command as the solve
    – guy
    Commented Apr 17, 2020 at 22:20
  • How would less commands make it easier to use? If you want to improve performance, you could first only check for a slot with a carrot on a stick and execute a function from there, which checks the durability dependent on that slot. It's slightly more commands in total, but only 37 of them run when you have no carrot on a stick, only 37+25 run when you have one, only 37+25+25 run if you have two etc. Commented Apr 17, 2020 at 23:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .