Minecraft – How to test for blocks within a certain radius of a player

minecraft-commandsminecraft-java-edition

I'm trying to make a custom crafting system, but I'm not sure how to test for blocks within a radius of players, not command blocks. Specifically, I'm attempting to test if there is a dropper within ten blocks of a player at any given time and any given place in the world. Is there a way to do this?

Best Answer

This can be done via the /fill command within /execute.

/execute @a ~ ~ ~ fill ~10 ~10 ~10 ~-10 ~-10 ~-10 pumpkin 0 replace dropper 1

/execute @a ~ ~ ~ fill ~10 ~10 ~10 ~-10 ~-10 ~-10 dropper 1 replace pumpkin 0

You don't have to use a pumpkin, any unused block will do. Put these two commands separately on a fill clock and run a comparator out from either of the two command blocks with the commands in them. Whenever any player is within 10 blocks (including diagonals, unfortunately) of a dropper with the data value of 1 (was that facing down? I can't remember), the comparator will turn on. Whenever they move out of range, it will turn off. That's currently the closest you can get to what you asked.