I am trying to modify the armor a certain entity is wearing (based on material) by adding a very slight movement speed decrease, which I should be able to do with attributes. I have the entity tagged so I can access it with /execute as @e[tag=…] run .
According to the internet, /item modify is the way to do this, yet there are no examples or command generators I could find. I found plenty of ways to get items with attributes through the /attribute and /give commands, but no examples for /item modify.
I currently have:
item modify entity @s armor.feet __________In the blank location, I attempted to fill this with the following words: set_attribute, attribute, etc. Regardless of what I seem to put in the "modifiers" spot, it always returns unknown item modifier.
How would I add a custom movement speed attribute decrease to it? It's probably easy but I can't seem to figure it out.
11 Answer
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.
/lootis 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.jsonwhere
stone_loot.jsonis that loot table above, andgive_loot.mcfunctionis the function with the/lootcommand.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_lootas 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 modifyis 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.jsonwhere
sharpness_two.jsonis that item modifier above, andmodify_mainhand.mcfunctionis the function with the/item modifycommand.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_lootas 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.
5