How do I use the "SelectedItem" tag to check for a player in this command?
Solution 1:
The main problem with your command is that you have an extra set of square brackets after SelectedItem
; that is, ...SelectedItem:[{id:"mi...
should really be ...SelectedItem:{id:"mi...
A square bracket [
tells Minecraft that the specified tag is a list (for example ArmorItems:[{},{},{},{}]
), where as a curly bracket {
tells Minecraft that the specified tag is a single item (with attributes).
I'm assuming that you should also use an at @s
to tell Minecraft to run at the player's coordinates and specify the block you want to fill. This turns out as
/execute as @a[nbt={SelectedItem:{id:"minecraft:grass_block",tag:{display:{Name:"{\"text\":\"GRASS3x3\"}"}}}}] at @s run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 grass_block