Minecraft – Testing for a block in a certain radius

minecraft-commandsminecraft-java-edition

I am making an arrow that explodes when it hits anything, but I need a way to testfor all blocks within a radius of 2 blocks to see if they're air or not. The only problem is, I dont know how.

Best Answer

Rather than testing for air blocks, why not use the inGround datatag for this:

First create a scoreboard:

/scoreboard objectives add arrow dummy

Then, run these 2 commands on a fast clock:

/scoreboard players add @e[type=Arrow] arrow 1 {inGround:true}
/execute @e[score_arrow_min=1] ~ ~ ~ summon Creeper ~ ~ ~ {Fuse:1,ignited:1,ActiveEffects:[{Id:14,Amplifier:1,Duration:999999}],powered:true}

Happy exploding :)