TransWikia.com

Execute command as you drink a water bottle

Arqade Asked on April 29, 2021

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?

One Answer

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

Correct answer by user232393 on April 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP