How do I do the equivalent of /testfor in Minecraft Java Edition 1.17.1? [duplicate]
I have a system set up to trigger a command block if an entity walks to that spot. However, it is setting off the trigger without an entity being there. This is the command that I'm using:
execute if entity @e positioned -86 5 82 run fill -88 4 79 -88 4 79 minecraft:redstone_block
Why is my command running even when an entity is not in that location?
Your command is testing for an entity with the selector @e
, which is any entity. This will almost always be true while you are on the world / server.
The positioned
means that the command is ran from the location, so if you did /execute positioned x y z run setblock ^ ^ ^ stone
then the block at x y z would be set to stone.
The correct version of this command would be:
/execute positioned x y z if entity @e[distance=..1] run fill xyz1 xyz2 block
And obviously you would replace x y z, xyz1, xyz2 and block with your own data.