Minecraft – (Java Minecraft 1.14) How to give effects in a function rewarded by an advancement

minecraft-commandsminecraft-data-packsminecraft-java-edition

I have a function triggered by an advancement that is supposed to give the player nausea and strength. It looks like this:

tellraw @s [{"text":"[","color":"dark_aqua"},{"selector":"@s","color":"dark_aqua"},{"text":"] ","color":"dark_aqua"},{"text":"I feel ill...","color":"aqua"}]
effect give @s minecraft:nausea 30 3 true
effect give @s minecraft:strength 30 1 true
advancement revoke @s only dark_magic:hidden/drink_blood

This is triggered by the player drinking a retextured milk bucket (a blood-filled bucket), which works fine. The advancement which triggers the function is very simple and looks like this:

{
  "criteria": {
    "drink_blood": {
      "trigger": "minecraft:consume_item",
      "conditions": {
        "item": {
          "item": "minecraft:milk_bucket",
          "nbt": "{BloodBucket:1b,CustomModelData:1}"
        }
      }
    }
  },
  "rewards": {
    "function": "dark_magic:progression/story_dialogue/i_feel_ill"
  }
}

When I drink a milk bucket with the custom NBT tag BloodBucket:1b, it works: the /tellraw triggers, and the advancement is revoked, reseting everything so I can drink it again and it will still work. However, the /effect commands don't work. I can run the function manually from the chat, as in /function dark_magic:progression/story_dialogue/i_feel_ill, and the effects work fine, but when run by the advancement, they don't work at all.

Does anyone know why this is? Moreover, does anyone know how to get around this? I know I could tag the player as drank_blood or something and /schedule a function for 1 tick later which executes the effects as all players tagged with drank_blood and removes the tag, but that seems unnecessarily complicated for something as simple as giving an effect.

Am I doing something wrong with a selector or missing something simple, or is this just not possible and I'll need to do the /schedule method?

Best Answer

A long search for the cause, a short and simple answer:

Functions that are rewards for an advancement triggered by the consume_item trigger are executed before the item does what it does. For example your function first gives its effects to you, THEN the milk bucket clears all effects and the empty bucket it put into its slot.