Here's the command I've tried:
/execute at @p[nbt={SelectedItem:{id:"minecraft:netherite_sword"}}] run effect give @p minecraft:strength 1 2
This works on all netherite swords.
How do I get it to work with only a custom named netherite sword?
Arqade is a question and answer site for passionate videogamers on all platforms. It only takes a minute to sign up.
Sign up to join this communityHere's the command I've tried:
/execute at @p[nbt={SelectedItem:{id:"minecraft:netherite_sword"}}] run effect give @p minecraft:strength 1 2
This works on all netherite swords.
How do I get it to work with only a custom named netherite sword?
There's a lot of unnecessary data in Alexander's answer, but it would work on a brand new sword with zero damage and zero prior repairs. A condensed version of his command that works on all custom-named netherite swords would be:
/execute as @a[nbt={SelectedItem:{id:"minecraft:netherite_sword",tag:{display:{Name:'{"text":"REPLACEME"}'}}}}] run effect give @s minecraft:strength 1 2
Change REPLACEME to the name of the sword. Note that this gives strength 3, because it adds 2 levels of strength to the base level of 1.
You can see the command structure here:
execute as //execute the command as the target
@a //select all players
[nbt={ //check their NBT data
SelectedItem:{ //check their selected item:
id:"minecraft:netherite_sword", //check it is a netherite sword
tag:{ //check it has a tag
display:{ //check that it's a display tag
Name:'{ //check that it's a Name tag
*/note the ' before the {
*/if it's not present the command breaks
"text":"REPLACEME" //check that the exact text is REPLACEME
}'
}
}
} //if all of the above is true
}] run effect give @s minecraft:strength 1 2 //give the holder of the sword strength 3
You could try getting the data of the sword using the command:
/data get entity @s SelectedItem
and pasting it like that:
execute as @e[nbt={SelectedItem:{id: "minecraft:netherite_sword", Count: 1b, tag: {RepairCost: 0, Damage: 0,
display: {Name: '{"text":"<name_of_the_sword>"}'}}}}]
run effect give @s minecraft:strength 1 2
At least that's how I would do it.