Minecraft – Detect entities affected by instant health and damage potions

minecraft-commandsminecraft-java-edition

I want to execute a command to entities affected by instant health potions (Potion, Splash, Lingering).

The command execute as @e[nbt={ActiveEffects:[{Id:6b}]}] run <command> only works if the entity is affected through effect give.

Any idea how?

Best Answer

"Instant health" is instant. You don't even have it for a single tick, it just applies its health effect and then disappears again. That the effect exists at all is pretty much an implementation detail.

So no, you cannot detect entities that are affected with it. The best you can do would be to detect a splash potion with that effect that is close to the entity and then disappears (like it's done for snowballs) and also detect using the potion directly using the scoreboard type for that (does not work for witches) and also being inside an AreaEffectCloud with that effect (which requires checking its size).

Alternatively, you could use a different potion, like "Unluck", replace all Instant health potions in inventories with Unluck potions (like here) and maybe also the effects of splash potion entities, then execute your commands on entities with that effect, of which the first two commands are giving an Instant health effect and removing the Unluck effect. You can then use a resource pack to replace the name, icon, etc. of Unluck potions to make them appear as Instant health potions. I don't know which of the two methods is easier.