3

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?

  • While I haven't worked with Minecraft commands much, could you get the coordinates of the player, then check which block is present in the space directly below them? – SaintWacko Mar 11 '15 at 17:05
  • 2
    @SaintWacko I think... you can, probably. Maybe like an excute @p testforblock air ~ ~-1 ~ or something? – Unionhawk Mar 11 '15 at 17:30
8

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)

| improve this answer | |
  • Very good catch with this tag! But why wouldn't you just test for {OnGround:0b} instead of inverting the output? – MrLemon May 27 '15 at 10:01
  • 1
    Another thing I'd add is that you can use NBT data for assigning scoreboard objectives, which can be utilized in target selectors for commands that do not natively support data tags. I.e. /scoreboard players set @a grounded 1 {OnGround:1b} – MrLemon May 27 '15 at 10:04
6

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]

| improve this answer | |
  • 1
    I suggest setting the detect range to ~ ~-2 ~, otherwise, you might affect people who are simply jumping around rather than falling. – MrLemon Apr 20 '15 at 9:13
  • 1
    @MrLemon That would work, but the people might want to affect jumping players as well. – xornob Apr 20 '15 at 21:47
1

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)

| improve this answer | |
  • This looks really cool when you kill a player with the effect. They go flying in the air. – user88078 Oct 12 '15 at 19:44
0

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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.