Steps to reproduce:
Join a new Creative world.
Get any sword from the menu and hold it.
Run the following command multiple times:
/item modify entity @s weapon [{"function":"minecraft:enchant_with_levels","levels":30,"options":"#minecraft:on_random_loot"}]
In this example, a Sword enchanted with Sharpness, Smite and Bane of Arthropods was obtained, as shown on the image below. This is inconsistent with the 'enchant_randomly' function, which can be specified to only enchant the item with compatible enchantments.
[media]Attachments
Comments 3
Can confirm. I've experienced the same issue back since 1.16.5, but it likely has existed well before that. I've seen references to `"function":"minecraft:enchant_with_levels"` all the way back in 2016. I haven't tested on any versions prior to 1.16.5, however.
I suspect this has also been an issue in versions way before 1.21, however I did not see any report regarding this. If it is a duplicate though, then I am terribly sorry for the inconvenience.