I've been working on an "infinite elytra flight" thingy and came across into an issue. I want to make the player goes up when reaching a certain distance from the ground.

I know I can use the command

/testfor @p [x=coord y=coord z=coord]

This command can /testfor a player's y coordinates, but how to detect his/her relative altitude from the ground?

  • Why downvote, please explain so I can improve it. – stevefestl Jun 9 '17 at 11:36
  • 1
    You're unlikely to get an answer as to why your question was downvoted, but on the whole, I think it's a good question. I typically recommend against the use of testfor, but it might be useful here. – MBraedley Jun 9 '17 at 11:58
  • Have you made any attempt to solve this yourself? Arqade works better when askers show effort to solve their own problems; we see that you have a problem you've worked on, and answerers respond to that. You also get a more specific answer that's tailored exactly to the part you're stuck, and Arqade gets a very specific question. Everybody wins! – Frank Jun 9 '17 at 12:04

NOTE: I am not 100% familiar with Minecraft commands, but I may have found a way according to the wiki.

You can use the /testforblock command to check whether a certain block is in a certain location. This command can be run using the Tilde notation (~3, for example), to get a relative location towards the command execution. You can then prefix that with the /execute command to execute it at a player's location.

Another thing you can do is instead of using coordinates is specifying a radius using [r=R].

putting those together, you can do one of 2 things:

  1. find a player and test if any of the common "top layer blocks" like sand, gravel, stone, dirt or grass blocks are within X blocks on the Y Axis. If the command is true, teleport the detected player upwards..

  2. for every top block in the infinite elytra area, select all players that are within a certain range and teleport them upwards.

  • I don't think you can use the [r=R] selector like this. That changes which entity gets selected, but with testforblock, you not dealing with an entity. – MBraedley Jun 10 '17 at 1:52

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.