Testing for a block in a certain radius

Testing for a block in a certain radius - Woman in Red Shirt Holding Her Face

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 :)




Pictures about "Testing for a block in a certain radius"

Testing for a block in a certain radius - Brown and White Brick Wall
Testing for a block in a certain radius - White and Brown Brick Wall
Testing for a block in a certain radius - Woman in White Hijab Holding Clear Plastic Container



How do you Testfor a player in a radius?

2. Type the Command
  • Test if Players are within 10 blocks. In this example, we will test to see if there are any players within a 10 block radius with the following command: /testfor @a[r=10] ...
  • Test if Mooshrooms are within 50 blocks. ...
  • Test if Nearest Player is at Level 20 experience.


  • How do you test for blocks?

    You can test whether there is a certain block at a specific location in the game using the /testforblock command in Minecraft. TIP: Starting in Minecraft Java Edition (PC/Mac) 1.13, the /testforblock command was removed from the Java Edition version of the game.

    How do I find a specific block in Minecraft?

    The blank is for the particular block you are looking for. Let's say you're lost in the Nether and need to find your Nether Portal, you could type : /locateblock obsidian, and get the coordinates for the nearest obsidian, most likely being your, said, Portal.



    Detect When A Player Is At A Block/Blocks Minecraft




    More answers regarding testing for a block in a certain radius

    Answer 2

    You can use the testforblocks command to easily check for whether an area contains only air or not, but it would require a designated area which must remain empty at all times. If this is on a server, you may want to encase this region in bedrock and "hide" it underground somewhere. As an example of usage, you would want to type

    /testforblocks 0 60 0 3 63 3 30 70 30
    

    if the empty area was (0,60,0) to (3,63,3) and the area to check for emptiness was (30,70,30) to (33,73,33). Technically speaking, the two regions could be switched without any noticeable effect on the result. I would imagine that in your particular case, you'd want something more along the lines of

    /execute @e[type=Arrow] ~ ~ ~ /testforblocks 0 60 0 3 63 3 ~-1 ~-1 ~-1
    

    along with whatever else you plan to do. Hope that helps!

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

    Images: Pavel Danilyuk, Alex Tepetidis, Alex Tepetidis, Rizki Koto