0

I'm making a flying map where players are not allowed to touch grass, quartz, or leaves. If they do, I need them to be teleported to the start. How can I do that? By the way, this is 15w47c map.

2
  • Get player locations, check Y maybe?
    – ave
    Nov 22 '15 at 16:02
  • I edited it, so it is no longer a duplicate of the linked question. Could we get some moderators to start a reopen vote?
    – ash4fun
    Mar 28 '16 at 13:48
1

Try this:

execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:grass -1 tp @a[c=1] <x> <y> <z>

That checks if the player is on top of a grass block. Just change the relative coordinates (the ~ ~-1 ~) in order to check above, right, etc. And, obviously, change minecraft:grass to whatever block you want to check. If you have issues with the relative coords, check them out here.

5
  • I'm not an expert on commands but there's a "not equal" check too, right? So you could test instead that they're not above air?
    – Studoku
    Nov 22 '15 at 16:29
  • @Studoku Well, you could just put execute @a ~ ~ ~ testfor @e[type=Air] ~ ~1 ~ and put a redstone inverter circuit next to the comparator. There probably is a way to put not equal, but this is easier :P
    – APCoding
    Nov 22 '15 at 16:33
  • If I had to guess, I'd guess !=
    – Studoku
    Nov 22 '15 at 16:40
  • @Studoku Does my solution work? Also, != is the operator in many programming languages for not equal to, so that's a good guess!
    – APCoding
    Nov 22 '15 at 16:41
  • The @e selector (as well as /testfor) is to target entities. The type parameter specifies an entity ID (list). Blocks are not entities and no target selector can target blocks. You must use a command that works with blocks, such as /testforblock, but /execute has syntax for detecting a block anyway: /execute <target> X Y Z detect X Y Z <block> <Damage> <command>
    – Skylinerw
    Nov 22 '15 at 20:57
0

The OnGround byte tag specifies whether or not the player is on the ground. You can assign a score based on its value and target the player based on that score:

/scoreboard objectives add OnGround dummy

/scoreboard players set @a OnGround 1 {OnGround:1b}
/scoreboard players set @a OnGround 0 {OnGround:0b}

/tp @a[score_OnGround_min=1] X Y Z

Another method is to detect whether there is air at the player's current feet position, but keep in mind that this method is flawed when it comes to players standing on non-full blocks such as slabs:

/scoreboard players set @a OnGround 1
/execute @a ~ ~ ~ detect ~ ~ ~ minecraft:air 0 scoreboard players set @a[c=1] OnGround 0

For 15w47c+, you can use the "tags" feature to avoid having to use scoreboard objectives:

/scoreboard players tag @a[tag=!OnGround] add OnGround {OnGround:1b}
/scoreboard players tag @a[tag=OnGround] remove OnGround {OnGround:0b}

/tp @a[tag=OnGround] X Y Z

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