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.

  • What does "it doesn't work" mean? Error message? Computer explodes? Chickens everywhere? Also, can you please reword the first paragraph? It's a bit hard to understand with its 61 words and three "and". – Fabian Röling Mar 16 at 22:04
  • Sorry for the confusion, I changed it and hope it's easier to understand now. – IHaveQuistion Mar 17 at 1:35

You're testing for a stack size of 0. That can't ever happen. Change it to Count:1b.

  • That would make it work but I don't want the bar to reload until the player has thrown the snowball. – IHaveQuistion Mar 18 at 11:22
  • I think I figured out how to make it work, I just need to add a scoreboard objective once the player throws the snowball, the objective resets if the player throws the snowball and only players who don't have that objective have their xp bar refilled. – IHaveQuistion Mar 18 at 11:25
  • You're old solution should work without that, but your new solution is better. – Fabian Röling Mar 18 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.