I was working on a quick creation that used a diamond pickaxe to mine blocks under you that were grass in a 3x3 area. I tested it and it didn't work and was executing under the command block, so I added the "as" component to use the entity the command found with a if component:
execute if entity @a[nbt={SelectedItem:{id:"minecraft:diamond_pickaxe"}}] as @s if block ~ ~-1 ~ grass_block run say Test
if entity @a[nbt={SelectedItem:{id:"minecraft:diamond_pickaxe"}}] checks all the players in the world that has a diamond pickaxe in their main hand, I was hoping that adding as @s would also grab the entity that it found but then the code breaks
Comments 8
execute if entity @a[nbt={SelectedItem:{id:"minecraft:diamond_pickaxe"}}] at @s if block ~ ~-1 ~ grass_block run say Test
Still didn't work
execute at @a[nbt={SelectedItem:{id:"minecraft:diamond_pickaxe"}}] if block ~ ~-1 ~ grass_block run say Test
Your "if" and "@s" are making it wrong
Found it out facepalms it's because it was using 2 if components, if I didn't add the if block then it wouldve worked but you can only have 1 if component
This is not a bug, it's just a misunderstanding of the command. To execute at a player, use
/execute at
, notif
oras