Minecraft Java Edition – How to Destroy Certain Blocks within the Range of an Entity

minecraft-java-edition

I am trying to find out how to destroy certain blocks in the range of an entity.
Example

Command block detects that cracked stone bricks is in range of the TNT item entity and then destroys the cracked stone bricks.

Best Answer

It's pretty simple. All you need are two commands in repeat command blocks, and to add a new scoreboard objective.

First, run this command once:

/scoreboard objectives add TNT dummy

Then in the first command block (set to repeat mode):

/scoreboard players set @e[type=Item] TNT 1 {Item:{id:minecraft:tnt}}

Finally, in a second command block (also set to repeat):

/execute @e[score_TNT_min=1] ~ ~ ~ fill ~2 ~2 ~2 ~-2 ~-2 ~-2 minecraft:air 0 replace minecraft:stonebrick 2

This will replace any stone bricks in a 5x5x5 cube around the item with air. I haven't tested this, so it might not work, but I think it will. Good luck!