Minecraft – How to set a command block in Minecraft 1.9 to send out a redstone signal whenever it detects a player on a specific type of block

minecraft-commandsminecraft-java-edition

I'm trying to recreate a form of the game Runner in a spleef format. Basically, I want a redstone signal to be sent out when the player stands on a Snow block in order to delete the block (replace it with air using setblock) a second or two after. How would I accomplish this?

Best Answer

The /execute command will allow you to detect blocks relative to a player. The syntax is:

/execute <entity> <x> <y> <z> <command>

So, you can run the following in the command block:

execute @p ~ ~ ~ testforblock ~ ~-1 ~ snow

The above will give a redstone signal when it successfully finds a snow block below the player, which is what your question asks.

However, using testfor commands and comparators for something like this is generally a bad idea; how will you know what block to delete 2 seconds later when the player has moved away from it, for example? Plus it'll be completely incompatible with multiplayer.

You may want to, instead, use the /execute command's detect syntax, which allows you to detect a block from an entity, then run a command from the same entity if that block was found. You could use this to delete the block that was found, or summon a marker stand to delete it after a delay:

execute @a ~ ~ ~ detect ~ ~-1 ~ snow 0 summon ArmorStand ~ ~-1 ~ {Marker:1b,Invisible:1b,NoGravity:1b,Invulnerable:1b,CustomName:"BlockRemover"}