Is there an easier way to detect for a block around the player?

Currently the easiest or most compact way to test for a block, say grass, around the player is by using an execute detect command for every block in a radius that you want. That means you would need 27 to test for a 1 block radius (3x3x3), one for each possible X, Y, and Z combimation (ex. detect ~ ~ ~ grass detect ~ ~ ~-1 grass detect ~ ~ ~1 grass detect ~ ~1 ~ grass etc.). This is even more of a problem if you are detecting for more than one block, meaning you could have over 70 for just 3 blocks, and we’re just talking about a 1 block radius here.

Is there a solution to this? an easier way, or a more compact way?

  • Redstone repeater delay if activated
  • Why is =! not working in testfor command?
  • How would I make something spawn when and where a snowball hits something?
  • Can mobs go through doors?
  • Does Herobrine exist?
  • Is there a way to see Minecraft's source code?
  • Do explosions destroy stuff?
  • MCPE give command components
  • Minecraft Empty Chests Command Block
  • How do I make a 1x1x2 piston door that opens when I step on a plate and not the other way around?
  • In Minecraft how do I randomise the output in a redstone circuit?
  • How much bandwidth does a Minecraft client use in SMP?
  • One Solution collect form web for “Is there an easier way to detect for a block around the player?”

    You can use a filtered /clone command that will copy blocks to their same position. The result is no difference visually, but the command can return a CommandStat value depending on its success.

    Prerequisites:

    Objective to hold the returned CommandStat value.

    /scoreboard objectives add BLOCKS dummy
    

    Applying the AffectedBlocks trigger to players, so that when they run commands, their own “BLOCKS” score will be set equal to the number of blocks affected. You may need this on a clock if new players can join at any time.

    /stats entity @a set AffectedBlocks @a[c=1] BLOCKS
    

    In order for CommandStats to modify a target’s score, they must be tracked on the scoreboard prior. This may need to be on a clock as well.

    /scoreboard players add @a BLOCKS 0
    

    Clock commands:

    The following must be run in order on a clock.

    1. Cause players to run a /clone command around them, looking for grass specifically. It will be cloned to the same position that they’re already in. This will return either the number of grass blocks found or 0. The target coordinates should be the same as the first specified corner.

      /execute @a ~ ~ ~ /clone ~-10 ~-1 ~-10 ~10 ~10 ~10 ~-10 ~-1 ~-10 filtered force minecraft:grass
      
    2. Players with a “BLOCKS” score of 1+ has grass around them. You can target them based on this value.

      /say @a[score_BLOCKS_min=1] has grass blocks around them.
      /say @a[score_BLOCKS_min=10] has at least 10 grass blocks around them.
      
    We love Playing Games, especially Video Games.