TransWikia.com

Is there any way to check if a player drank a specific potion?

Arqade Asked on March 7, 2021

I tried something like this:
scoreboard objectives add potion minecraft.used:minecraft.potion 0
But that went up every time I drank any type of potion. And this isn’t a command:
scoreboard objectives add potion potion{CustomPotionEffects:[{Id:1b,Amplifier:0b,Duration:2400}]} 0
So I would like some help with this.

One Answer

You can use the minecraft.used:minecraft.potion criteria in combination with a tag to do this. The criteria would be used to detect when the player drinks a potion and the tag would serve as an indicator that the player is holding the correct potion.

I put together a simple example of this concept. Just create this scoreboard objective:

/scoreboard objectives add potion minecraft.used:minecraft.potion

and paste the following commands into a chain of command blocks (repeating command block and some chain command blocks attached to it).

/tag @a[nbt={SelectedItem:{id:"minecraft:potion",tag:{CustomPotionEffects:[{Id:1b,Amplifier:0b,Duration:2400}]}}},tag=!correctPotion] add correctPotion
/execute as @a[scores={potion=1..},tag=correctPotion] run say drank healing potion
/tag @a[nbt=!{SelectedItem:{id:"minecraft:potion",tag:{CustomPotionEffects:[{Id:1b,Amplifier:0b,Duration:2400}]}}},tag=correctPotion] remove correctPotion
/scoreboard players reset @a[scores={potion=1..}] potion

Just replace the NBT data in SelectedItem with the data your potion has. I used the example you provided in your post.

Correct answer by MegaCrafter10 on March 7, 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