mojira.dev
MC-276702

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

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)

/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. ❌

 

Attachments

Comments 1

Thank you for your report!
After consideration, the issue is being closed as Working as Intended.

Please note, that mechanics of the game may change between updates.
Things such as graphics, sounds, world creation, biomes, redstone, villagers, and animals may not work the same in current versions.

Full Version HistorySnapshot Version HistoryThe official Minecraft feedback site

Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki

Triton365

(Unassigned)

Confirmed

Data Packs

1.21.1

Retrieved