How do I 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?

How do I 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? - Letter tiles of board game on table

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"}



Pictures about "How do I 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?"

How do I 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? - Set of red dice stacked together on wooden table placed on sunny terrace in daylight
How do I 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? - Top view of scissors against coil of twine and textiles with wooden block tied with threads on desk
How do I 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? - From above of anonymous barefoot boy and girl in casual clothes sitting on floor carpet and playing with wooden blocks of jenga tower game



How do you detect if a player is standing on a specific block?

A command block can execute commands when activated by redstone power.



How to detect a player using command blocks! | /execute command tutorial for 1.16 Minecraft Java




More answers regarding how do I 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?

Answer 2

/execute features a detect parameter:

/execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:snow 0 /setblock ~ ~-1 ~ minecraft:air 0 Parameter explanation:

@a : select all players

~ ~ ~ : execute at their position

detect : only execute if the following block is found

~ ~-1 ~ : check the block below the player

minecraft:snow 0 : check for snow with metadata = 0

/setblock ~ ~-1 ~ minecraft:air 0 : command to be executed by the player(sets the block below him to air)

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Matthias Groeneveld, Matthias Groeneveld, Teona Swift, Ketut Subiyanto