2

I need to execute a command as I drink a water bottle. I have made a scoreboard already.

scoreboard objectives add drinkPotion minecraft.used:minecraft.potion

But, the execute command that I used doesn't work because as I drink the potion, it turns into a glass bottle. (Water bottle is considered as a potion)

execute as @a[nbt={SelectedItem:{id:"minecraft:potion",tag:{Potion:"minecraft:water"}}},scores={drinkPotion=1..}] run command

Do any of you have a solution for this?

1
  • Why would you check for the item at all? Just use the scoreboard and nothing else. Commented Jun 22, 2019 at 13:58

1 Answer 1

2

You can have a tag that tells you if a player was recently holding a water bottle. These commands work for me, I put the first one into a repeating command block and the rest into chain command blocks:

/execute as @a[nbt={SelectedItem:{id:"minecraft:potion",tag:{Potion:"minecraft:water"}}}] run tag @s add holdsWater
/execute as @a[nbt=!{SelectedItem:{id:"minecraft:potion",tag:{Potion:"minecraft:water"}}},scores={drinkPotion=0}] run tag @s remove holdsWater
/execute as @a[tag=holdsWater,scores={drinkPotion=1..}] run <command>
/scoreboard players reset * drinkPotion

The first command tags any player who is holding a water bottle
The second command removes the tag from any player who is not holding a water bottle, unless they just used a potion
The third command executes a command as any player who was just drinking a potion and has the holdsWater tag
The last command resets the scoreboard objective drinkPotion

2
  • Well, that was a stupid question to ask that I deleted it. I actually didn't test it out yet when I commented. I just assumed it works without it.
    – Robomike
    Commented Jun 22, 2019 at 14:09
  • Well, you get the same problem as you had before when you remove the scores tag in the second command, it`s good that you ask if things are unclear though.
    – user232393
    Commented Jun 22, 2019 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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