Minecraft – How to TestFor Player on certain block

minecraft-commandsminecraft-java-edition

I am creating a map where the player can only step on certain blocks, and if he/she steps off, they die.

How do I run a testfor where it tests for if the player is on the path, and if the player goes off of the path?

Best Answer

Simple! The command is:

/execute @a ~ ~ ~ detect ~ ~-1 ~ bedrock 0

Where bedrock is the block, and 0 is the damage counter.

After the "0" you can run any command you want! For example:

/execute @a ~ ~ ~ detect ~ ~-1 ~ stone 0 kill @a[c=1]

kill is the equivalent of the /kill @p command

So with this you can do whatever you want with your path!