The "/enchant" command only works if a player is holding an item. Therefore, executing at an item which is not in a payers selected hand and changing it's enchants would be impossible with this command.
However, I would be possible using a "/data merge" command:
execute as @e[type=item,nbt={OnGround:1b}] run data merge entity @s {Item:{id:"minecraft:diamond_sword",Count:1b,tag:{Enchantments:[{id:"minecraft:sharpness",lvl:1s}]}}}
This command in particular would effectively turn any item on the ground into a diamond sword with the sharpness I enchant.
@s is a target selector from 1.12. In short, it targets the entity that executed (or ran) the command. So in this example, the @s is targeting the item, since it is the one executing the /data command. More on target selectors: https://minecraft.gamepedia.com/Commands#Target_selectors_in_Java_Edition
Can anyone explain to me why this is not working?
execute at @e[type=item,nbt={OnGround:1b}] run enchant @e[distance=..1] minecraft:sharpness 1
The "/enchant" command only works if a player is holding an item. Therefore, executing at an item which is not in a payers selected hand and changing it's enchants would be impossible with this command.
However, I would be possible using a "/data merge" command:
This command in particular would effectively turn any item on the ground into a diamond sword with the sharpness I enchant.
Thanks, but what does the "@s" command do?
@s is a target selector from 1.12. In short, it targets the entity that executed (or ran) the command. So in this example, the @s is targeting the item, since it is the one executing the /data command. More on target selectors: https://minecraft.gamepedia.com/Commands#Target_selectors_in_Java_Edition