/execute if entity relative coordinates
I’m looking for a way to execute a command if an entity is within a certain area of another one. More specifically, I want to know when a player is anywhere along an armour stands y axis to create a command run barrier around a watery area, I can’t use barrier blocks because it takes longer, and creates an annoying air pocket where there shouldn’t be one.
One way I found to do this was
/execute positioned ~ ~20 ~ run execute if entity @e[distance=..1]
But this would create a 1x1x1 sphere you need to be in to make the condition true, and I want it to be a 1x256x1 sphere.
So once more, I am asking is there a way to have an execute if entity command along one coordinate, in my case the Y coordinate?
Here is a command that would work for what I need, the problem is that I would have to run a separate command for every 2 blocks.
/execute if entity @e[x=20, z=30, distance=..2] run say You’re on my y axis!
You can use the target selector arguments dx
, dy
, and dz
to create a detection box instead of a detection sphere. This is how:
Instead of using x
, y
, and z
to specify the centre of the sphere, you use them to specify the lower northwest corner of the detection box, and use dx
,dy
, and dz
to specify the width, height, and length of the target box. The box will extend east, up, and south the number of blocks you specify.
In your case, you can place the armour stand at the lower northwest corner of the detection box, and use the following commands:
/execute as @e[type=armour_stand,tag=test] if entity @e[dx=___,dy=___,dz=___]
Replace the first target selector with a way to target the armour stand, and replace the numbers in dx
,dy
, and dz
with the numbers you need.