TransWikia.com

Why do my commands not work in command blocks when they work correctly in chat?

Arqade Asked on July 13, 2021

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;

  1. (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.
  2. (C1) Looks for those who have the tag, and applies the indefinite Slow Falling.
  3. (C2) Looks for those both not between Y171 and Y189 and not in the boxed area, and removes the effect tag.
  4. (C2) Clears the Slow Falling effect for those without the effect tag.

Chain 3 is the problematic one. What it should do is the following;

  1. Searches for those without the effect tag between Y133 and Y171, and adds the tag in.

    execute as @a[tag=!effect,y=133,dy=38] at @s run tag @s add in
    
  2. Gives those with tag in Slow Falling for 10 seconds

    execute as @a[tag=in] at @s run effect give @s minecraft:slow_falling 10 1
    
  3. Removes tag in

    execute 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.

One 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.

Correct answer by ExpertCoder14 on July 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP