mojira.dev
MC-140569

Execute command inconsistent with "as" component

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

This is not a bug, it's just a misunderstanding of the command. To execute at a player, use /execute at, not if or as

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

Oh durr... you can add your if statement through the at component too

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

No, it's because if entity doesn't select any players, it just makes sure there are some anywhere in the world. The @s then refers to the command block since you never changed it with as, which causes an error because a command block is not an entity.

ArsiTheFox

(Unassigned)

Unconfirmed

command

Minecraft 1.13.2

Retrieved