Minecraft – How to detect if ANY block is broken using command blocks in Minecraft

minecraft-commandsminecraft-java-edition

So I want to detect if any player breaks any block using command blocks in Minecraft. I already know how to detect for specific blocks using scoreboards and the minecraft.mined criteria, but not ANY block.

Best Answer

Unfortunately, I don't think this is possible with vanilla command blocks although you could achieve this in a hacky way. The /cloning would probably create lots of lag, however. It would only look at blocks around the player, not if they shot an flame arrow at tnt far away. Also, it would find blocks other players, or an enderman or player moved or the player placed.

According to the fandom page on /clone you can test whether a player has broken any blocks by /cloning the region the player is in to another location far away, then /cloning the same region. If any blocks have changed, it should result in the number of blocks that were changed.

You could practically achieve this with command blocks. Every so often, spawn an invisible entity that floats where the player is, and clone a region of a set size around the player. After some time, clone that same regen around the spawned entity into the location you spawned the first one into and store the result into a variable with /execute store result. That variable is how many blocks were changed, whether created or destroyed.

There might also be a way to do a for loop for every block in a region to see if it was mined, although I do not know how to do it.