How can I check if a player is in the air with /testfor?

How can I check if a player is in the air with /testfor? - Smiling woman with chess looking at camera

I'm interested in negating fall damage with command blocks by giving players Resistance as they're falling. How can I use /testfor to tell whether a player is on the ground or in the air?



Best Answer

Try this:

testfor <player> {OnGround:1b}

Tests for specified player on the ground, then make a comparator to a NOT gate (Block with a redstone torch on it)




Pictures about "How can I check if a player is in the air with /testfor?"

How can I check if a player is in the air with /testfor? - Casting disc of modern car
How can I check if a player is in the air with /testfor? - Anonymous diver swimming near sunken plane
How can I check if a player is in the air with /testfor? - Brown Steel Letter B Wall Decor



How do you test if a player is sneaking in Minecraft?

How to Enter the Command
  • Test if Players are within 10 blocks. In this example, we will test to see if there are any players within a 10 block radius with the following command: /testfor @a[r=10] ...
  • Test if Mooshrooms are within 50 blocks. ...
  • Test if Nearest Player is at Level 20 experience.




  • Minecraft Redstone Tutorial | How to use testfor commands in MCPE!




    More answers regarding how can I check if a player is in the air with /testfor?

    Answer 2

    Let's make an objective to track this, and call it 'ground'.

    /scoreboard objectives add ground dummy
    

    This command needs to be executed only once.

    Then, on a fast clock, run

    /scoreboard players set @a ground 1
    

    and

    /execute @a ~ ~ ~ detect ~ ~-1 ~ air scoreboard set @p ground 0
    

    in that order.

    The first command sets all player to 'being on the ground', and the second command sets those who are in the air to not be on the ground.

    To affect players in the air, use @a[score_ground_min=0]

    To affect players on the ground, use @a[score_ground=1]

    Answer 3

    You only need 1 command: hook this up to a redstone clock:

    /execute @a ~ ~ ~ detect ~ ~-3 ~ air 0 effect @p jump_boost 1 255 true 
    

    It gives them infinite jump boost whilst in the air which prevents fall damage (they can still take fire damage, wither, etc)

    Answer 4

    testing if in air:

    execute @a[parameters] ~ ~ ~ detect ~ ~-1 ~ air 0 <command>
    

    testing if on ground:

    scoreboard objectives add onGround dummy
    scoreboard players set @a onGround 1 {onGround:1b}
    execute @a[score_onGround_min=1] ~ ~ ~ <command>
    scoreboard players set @a[score_onGround_min=1] onGround 1
    

    Answer 5

    /execute at @a if block ~ ~-3 ~ air run effect give @a minecraft:slow_falling 1 1
    

    I'm using this for 1.16.5 and it works in just one line (the effect can be different)

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Victoria Borodinova, Erik Mclean, Maƫl BALLAND, cottonbro