I'm in Java in 1.14.3 and I'm trying to create a custom mining tool using the stone hoe. Whenever the player mines with it, I want it to take durability/damage. I created a scoreboard scoreboard objectives add usedTool minecraft.mined:minecraft.stripped_spruce_log.
Now, whenever the player mines, I check if they have the stone hoe in their hand: execute as @a[nbt={SelectedItem:{id:"minecraft:stone_hoe"}}] if entity @s[scores={usedTool=..1}] run [...]
Is there a way I can subtract durability from the stone hoe after the player has mined with it?
Minecraft Java Edition Minecraft Commands – How to Subtract Durability From an Item Held in Hand?
minecraft-commandsminecraft-java-edition
Related Topic
- Minecraft – My arrows aren’t being executed at by a looping function/command block
- Minecraft Java Edition – How to Use /data Command with NBT Path in Minecraft 1.14
- Minecraft Java Edition – Losing Lots of Ticks on Command Functions
- Minecraft Commands – How to Use an NBT Editor to Modify Item Properties
Best Answer
You should use
execute store result entity @s SelectedItem.tag.Damage int 1 run <some command that returns a value>
. This will set theDamage
of the tool (how much it has been used) to the value of whatever command you put after the run. The 1 after theint
is a scale factor of 1.You can make a system where after the item is used, you store the durability somewhere with
execute store result score <entity> <objective> run data get entity @s SelectedItem.tag.Damage 1
,then usescoreboard players add <entity> <objective> 1
to add one to the value (because you are adding damage, effectively removing durability), and then use the aboveexecute store result entity @s SelectedItem.tag.Damage int 1 run scoreboard players get <entity> <objective>
to store that modified value back into theDamage
tag.