1

For I minecraft map I'm making I want to test whether or not a player has a specific potion in their inventory. How would one do this in 1.13+?

4
  • No, please delete the question if your original question isn't even really valid. Also, do you think it's this bug? bugs.mojang.com/browse/MC-149038 If yes, please state in a comment there which version you encountered this in and preferably also reproduction steps, because none are currently known. Commented Dec 23, 2019 at 14:46
  • I inteded more for it to be a self-answering question about how to check for specific potions in a player inventory, should I rewrite it into a question and answer, or just delete it anyway? Also, that does indeed sound like that bug, thx for linking, but I'm not sure if I can reproduce it.
    – Xander L
    Commented Dec 23, 2019 at 16:12
  • I did some testing a filed a bug report for the probable cause of what went wrong
    – Xander L
    Commented Dec 23, 2019 at 17:18
  • Re-writing it as a Q&A is of course better. Something like "how to do X in 1.13+", because /testfor no longer exists. Commented Dec 23, 2019 at 18:01

1 Answer 1

0

Using

 /data get entity @s 

on oneself while having a potion on you would reveal the Inventory NBT data you need for this command. Combing this with the answer for 1.13- given here:

How to test for specific potions in inventories?

the command would be something along the lines of:

execute if entity @p[nbt={Inventory:[{id:"minecraft:potion",tag:{Potion:"minecraft:mundane"}}]}] run say hi

where 'mundane' can be changed into the name of the potion wanted, for example: awkward, water or regeneration.

By replacing 'potion' into 'splash_potion' or 'lingering_potion' all other types of potions can be reached.

The normal extend potions can be searched for by changing 'mundane' to, for example, 'long_swiftness', level II potions can be searched for by changing 'mundane' to, for example, 'strong_swiftness'.

Custom potions are more difficult to detect, and can be detected using the following command:

\execute if entity @p[nbt={Inventory:[{id:"minecraft:potion",tag:{CustomPotionEffects:[{Id:1,Amplifier:2,Duration:1400}]}}]}]

where the number after Id represents the numerical ID of the potion effect as can be found on the wiki, the amplifier is the level of the potion effect, where level 0 is a normal potion effect, and the duration is the duration in game ticks (= 20 x length in seconds). All three of these identifiers are optional and if not set will default to be true for any potion.

If multiple effects need to be detected for some reason, replace the

CustomPotionEffects:[{...}] with CustomPotionEffects:[{...},{...}]

where every {...} has one or more of the Id,Amplifier,Duration tags, as above.

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.