Minecraft – How to test what block is underneath you

minecraft-commandsminecraft-java-edition

I want to test if any player is on a certain block. I want to kill them if they are standing on that certain block.

Best Answer

execute's detect syntax is useful for this.

In 1.11 and below:

/execute @a ~ ~ ~ detect ~ ~-1 ~ sponge * /kill @a[c=1]

In 1.12 and above:

/execute @a ~ ~ ~ detect ~ ~-1 ~ sponge * /kill @s

This will kill anyone standing on sponge. The * is where you would put the block state, e.g for wool color=red or stone variant=granite.