Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-276702

When a command triggers an advancement/enchantment, the function calls of its reward/entity_effect gets delayed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Works As Intended
    • None
    • 1.21.1
    • None
    • Confirmed
    • Data Packs

      There are things that can be triggered while a command is running, like advancements and custom enchantments, and the functions they call as a reward/entity_effects seem to be delayed.

      For example, in advancements, one of the ways to trigger the item_durability_changed criteria is to get hit by a mob while wearing armor, and its reward function is usually called before health is updated. If you have your reward function output the player's health, and you get hit by a mob while wearing armor, you can see that the output is the health before taking damage. However, if you use the /damage @s 3 arrow command instead of taking damage from the mob, you will see that the output is the health after taking damage. This is inconsistent.

      In custom enchantments, the problem is even worse (and more visible). For example, the location_changed effect component is triggered when the wearer's integer coordinates change, and its list of effects are applied in order. This is perfectly normal. But there is also a way to trigger this with a command, such as switching from spectator to survival with the /gamemode command, in this case, this will delay the function call to the last in the list of effects. This causes a problem if the order between effects is really important.

       

      Here are the steps to reproduce this behavior.

      1. Apply the attached datapack to your world. (you'll need to rejoin the world)
      2. /give @s netherite_helmet[enchantments={"test:test":1}]

        This enchantment has a location_changed effect component, with the effects that call the first function, give a luck status effect of 0.05 seconds, and call the last function. These two functions are supposed to print the wearer's current status effect, so the first function should not output any effects, and the last function should output luck.

      1. Try moving around. As mentioned above, only the last function will print luck, which is normal behavior.
      2. Change the gamemode to spectator and then back to survival. This time, both first and last functions output luck, which is abnormal behavior.

       

            Unassigned Unassigned
            Triton365 Triton365
            Votes:
            5 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: