Add armor attributes with /item modify- 1.17 datapack issue
Solution 1:
An item modifier is a separate file in your data pack. Your question has the implication you already are using a data pack so that is what I will assume.
Let's use a concept from /loot
, and bring it over to /item modify
.
/loot
is used to call upon a loot table, see what items it generates, and output the generated items to the location you set. For example,loot give @p loot _________
In the blank is where you specify which loot table you want to call upon. But loot tables are separate data pack files. So you don't type a loot table's contents into the blank, you type the loot table's ID into the blank.
Say I have a loot table that drops one stone. That's a giant JSON file I have right there. As I stated above, I don't type its name into the blank, instead, I put that JSON file into the designated folder for loot tables, and call upon its name.
After doing this, my data pack structure looks like this:
my_datapack ├ pack.mcmeta └ data └ my_namespace ├ functions │ └ give_loot.mcfunction └ loot_tables └ stone_loot.json
where
stone_loot.json
is that loot table above, andgive_loot.mcfunction
is the function with the/loot
command.So to give the loot to the player, we call upon the filename of the loot table we made, formatted as
namespace:id
. In this case, we havestone_loot
as the ID, and our namespace ismy_namespace
. So the proper thing to type in the blank ismy_namespace:stone_loot
. This makes:loot give @p loot my_namespace:stone_loot
The above snippet should make sense to you. If it doesn't, please ask for clarification in the comments below.
It's the same concept for /item modify
. This is the exact same text, translated for item modifiers:
/item modify
is used to call upon an item modifier, look at the contents of said item modifier, and interpret the contents as instructions for how to modify the item in the slot you set. For example,item modify entity @p weapon.mainhand _________
In the blank is where you specify which item modifier you want to call upon. But item modifiers are separate data pack files. So you don't type an item modifier's contents into the blank, you type the its ID into the blank.
Say I have an item modifier that adds Sharpness II onto an item. That's quite the JSON file I have right there. As I stated above, I don't type its name into the blank, instead, I put that JSON file into the designated folder for item modifiers, and call upon its name.
After doing this, my data pack structure looks like this:
my_datapack ├ pack.mcmeta └ data └ my_namespace ├ functions │ └ modify_mainhand.mcfunction └ item_modifiers └ sharpness_two.json
where
sharpness_two.json
is that item modifier above, andmodify_mainhand.mcfunction
is the function with the/item modify
command.So to invoke our item modifier, we call upon the filename of the item modifier we made, formatted as
namespace:id
. In this case, we havestone_loot
as the ID, and our namespace ismy_namespace
. So the proper thing to type in the blank ismy_namespace:sharpness_two
. This makes:item modify entity @p weapon.mainhand my_namespace:sharpness_two
Does this make sense how the same concept is applied to more things?
Oh, and as for how to make the JSON files for loot tables and data packs? That's what the wiki is for, the official documentation. But if you find the wiki confusing, you probably will need a generator. Here is the most competent item generator on the block for data pack files. I like this website because it only gives you the names of text inputs, but doesn't tell you what they do. You will have to cross-reference the wiki to figure out what each thing does.