mojira.dev
MC-301582

Using selector in a set_name item modifier fails when run directly by server/datapack

To replicate, create a datapack with the following item modifier (in file data/test/item_modifier/set_name_selector.json):

{"entity": "this", "function": "minecraft:set_name", "name": {"selector": "@a"}, "target": "custom_name"}

Now create a function that calls it (in file data/test/function/test.mcfunction):

item modify entity @a hotbar.0 test:set_name_selector

Running this function directly works as intended. However, running it on minecraft:tick or scheduling it causes the "entity": "this" resolution to fail. This is pretty unintuitive in my opinion; I expected it to work as if an entity had run it. There should be a way to run the item modifier every tick without explicitly choosing an arbitrary entity to run it. The item modifier doesn’t even depend on the caller at all!

Comments 3

Running a function via the tick tag or the /schedule command has no executing entity since the server itself is the source, so naturally the selector in the item modifier cannot be resolved. Try calling the function through the /execute command. /execute as @a run item modify entity @s hotbar.0 test:set_name_selector should do the trick, but I don’t have the time to test it myself right now.

Yes, it works. I solved it by running execute as @e[limit=1,sort=arbitrary] run item modify entity @s hotbar.0 test:set_name_selector. I understand why the command fails, I just think that requiring workarounds like this is pretty convoluted and unintuitive.

I guess it is working as intended though.

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

You have posted a feature request or a suggestion. This site is for bug reports only.
For suggestions, please visit https://feedback.minecraft.net

Quick Links
📓 Issue Guidelines – 💬 Mojang Support – 📧 Suggestions – 📖 Minecraft Wiki 

CzarBatata

(Unassigned)

Unconfirmed

(Unassigned)

1.21.8

Retrieved