I am trying to use the xp bar as a shot reloader where it gives a player a snowball when it reaches 1 xp level. It then stops adding xp points until the player throws the snowball, after which it will be set back to 0 xp. After that, it will load until it reaches 1 xp and give the player another snowball. The command sequence I'm using is:
Command block 1, impulse, activated by redstone circuit:
xp add @p[level=0] 1 points
Command block 2, impulse, always active:
give @p[level=1] snowball
Command block 3, impulse, always active:
xp set @p[nbt={Inventory:[{id:"minecraft:snowball",Count:0b}]}] 0 level
It works until the player throws the snowball. Once the snowball is thrown the xp level won't be set back to zero, meaning the player can't get snowballs again.