I'm attempting to make a system in which gives a player Slow Falling "indefinitely" when in a certain area/height (specially, in a specified rectangular are and from Y171 to Y189), then replacing it with the same except of 10 seconds instead when within a certain height lower than that (Y133 to Y171).
To do this, I've created a command system that does the following;
- (Chain 1) Looks for a player in the jumping area who doesn't have the tag
effect. (the reason why I wanted Slow Falling). Then, gives them that tag. - (C1) Looks for those who have the tag, and applies the indefinite Slow Falling.
- (C2) Looks for those both not between Y171 and Y189 and not in the boxed area, and removes the
effecttag. - (C2) Clears the Slow Falling effect for those without the
effecttag.
Chain 3 is the problematic one. What it should do is the following;
Searches for those without the
effecttag between Y133 and Y171, and adds the tagin.execute as @a[tag=!effect,y=133,dy=38] at @s run tag @s add inGives those with tag
inSlow Falling for 10 secondsexecute as @a[tag=in] at @s run effect give @s minecraft:slow_falling 10 1Removes tag
inexecute as @a[tag=in] at @s run tag @s remove in
The commands work perfectly fine on their own in chat, sent one-by-one. Attempting to put them in a command chain causes them to do absolutely nothing. I've never seen this happen before, and I can't seem to figure out why.
21 Answer
The problem is with your target selector @a[tag=!effect,y=133,dy=38]. When you specify dy without specifying dx or dz, they are automatically added and default to 0. This means that the game is testing for a one block wide and long area. So in reality, the game is actually testing for @a[tag=!effect,y=133,dx=0,dy=38,dz=0]
The only reason why your commands work in chat is because when you are typing them in chat, the position that the selector calculates from is set to your location, meaning it creates its detection box starting from your position, so your hitbox will always be touching it, so it always succeeds. When you put it in a command block, the detection box is created from the command block's position, and you won't always be in that area.
To fix this, you can use a predicate to detect entity position, this is not subject to the rule that you must have all three at once.
5