I was just wondering how the entitydata command worked on dropped items. If i dropped a sword on the ground, could I use the entitydata command to change it's attributes (speed/health when held, etc.) or enchant the sword or change it's durability?
Actually, it only requires one command block (as of 1.13).
Use this command inside of a repeating command block: execute as@e[type=item,nbt:{Item:{id:"#item id here (example minecraft:iron_sword)#"}}] at @s run data merge entity @s {Item:{tag:{#item nbt here (example Enchantments:[{id:sharpness,lvl:5}])#}}}
I was just wondering how the entitydata command worked on dropped items. If i dropped a sword on the ground, could I use the entitydata command to change it's attributes (speed/health when held, etc.) or enchant the sword or change it's durability?
This would change the closest item to you or the command block it is executed from to an Iron Sword with Sharpness V:
/entitydata @e[type=Item,c=1] {Item:{id:minecraft:iron_sword,Count:1,tag:{ench:[{id:16,lvl:5}]}}}
This would change its durability to 220/250:
/entitydata @e[type=Item,c=1] {Item:{id:minecraft:iron_sword,Count:1,Damage:30}}
This would give the iron sword an Attribute that increases speed by 20%:
/entitydata @e[type=Item,c=1] {Item:{id:minecraft:iron_sword,Count:1,tag:{AttributeModifiers:[{AttributeName:generic.movementSpeed,Name:;generic.movementSpeed,Amount:0.2,Operation:1,UUIDMost:29663,UUIDLeast:179958}]}}}
Unfortunately there isn't really a way that you can only change an item that is an iron sword to start with.
(Well, there might be, but it would be very, very complicated).
Actually, it only requires two command blocks.
First command block: /scoreboard players set @e[type=Item] <scoreboard_name> 1 {Item:{id:"minecraft:iron_sword"}}
Second command block: /execute @a ~ ~ ~ /entitydata @e[type=Item,r=5,score_<scoreboard_name>_min=1] {Item:{tag:{ench:[{id:16,lvl:5}]}}}
If you connect this to a clock, it will make any iron sword within five blocks of a player be enchanted with Sharpness V.
Actually, it only requires one command block (as of 1.13).
Use this command inside of a repeating command block: execute as @e[type=item,nbt:{Item:{id:"#item id here (example minecraft:iron_sword)#"}}] at @s run data merge entity @s {Item:{tag:{#item nbt here (example Enchantments:[{id:sharpness,lvl:5}])#}}}