1.15.2 - How do I test for if a player's inventory is open?

I'm trying to do something that gives you mining fatigue while your inventory is not open, but stops whenever it is opened. I would appreciate some help with this. Is there an NBT tag for this?


Solution 1:

If they're never meant to mine any blocks, just put them in Adventure mode.

If they're meant to be able to mine a certain type of block, tools have NBT tags that allow them to mine one type of block only (they still need to be in Adventure mode):

1.12-: /give @p minecraft:diamond_pickaxe 1 0 {CanDestroy:["BLOCK_HERE"]}
1.13+: /give @p minecraft:diamond_pickaxe{CanDestroy:["minecraft:BLOCK_HERE"]} 1

If they're only not meant to be able to mine blocks in a certain area, put pressure plates activating Adventure mode at the entrance to it, and activating Survival Mode at the exit to it.