Minecraft – How to make blocks disappear when you go near them

minecraft-commandsminecraft-java-edition

I would like to know how to make it so that when you go near a certain block that block will disappear. I'm also looking for something where the command block is not where the disappearing block will go. What is the command to do this?

Best Answer

Have a command block testing for a player within a certain radius from the block coords:

/testfor @a[x=X,y=Y,z=Z,r=R]

(Where X Y Z are the coordinates of the block you want to disappear, and R is the distance you want it to disappear from)

Then have a comparator on that leading directly to a command block removing the you want to disappear:

/setblock X Y Z air

(Again, where X Y Z are the coordinates of the block you want to disappear.)

You could also simplify this down into one command like this:

/execute @a[X,Y,Z,R] ~ ~ ~ /setblock X Y Z air