1

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.

1
  • At the end, your core question needs to focus on just the item you need help with, or presume you need help with. No detail was removed in my edit but some stuff was shuffled around. As for your answer, no one has seemed to write about this topic before in a concise way, so I shall do so in an answer now.
    – One 2 Many
    Commented Oct 25, 2021 at 5:53

1 Answer 1

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, and give_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 have stone_loot as the ID, and our namespace is my_namespace. So the proper thing to type in the blank is my_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, and modify_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 have stone_loot as the ID, and our namespace is my_namespace. So the proper thing to type in the blank is my_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
  • Well the second to last paragraph was a bit rude, but anyways I've actually found another datapack recently that also adds attributes and thats how it added them, but I didnt understand why he did it that way and I was hoping there was an easier way such as using just the attribute modify command. Regardless, thank you for clarifying, and it should hopefully work. Ill try it soon and edit the question if it doesnt work.
    – Aceplante
    Commented Oct 25, 2021 at 13:09
  • @Aceplante Hey there, sorry for sounding rude. I have to admit that it was a little frustrating to me that you used data packs but couldn't understand how the connection between files applies to more than one thing. I meant for that paragraph to be more of a question than a reprimand, but seems like my emotions got in the way, and looking at this for the second time, yea it does sound a little rude, sorry about that. Anyways I'll get rid of that section and if you need additional help, don't hesitate to ask.
    – One 2 Many
    Commented Oct 25, 2021 at 17:54
  • Update, it does not seem to be working. All the commands seem right, but the output keeps showing that tick fails because there's 'no reference' even though the file "weight" is in the same folder as everything else. Everything else which by the way was working fine until I added this new one weight. Why would this be happening? Does this mean the issue is with the weight file? if so should I copy and paste it here? Oh and the exact error is pasted here: "Couldn't load tag minecraft:tick as it is missing following references:"
    – Aceplante
    Commented Oct 25, 2021 at 18:04
  • Hm, interesting. Would you mind discussing on chat? Seems like you might need some live help.
    – One 2 Many
    Commented Oct 25, 2021 at 19:23
  • So apparently theyre json files not mcfunction. It has been fixed and should work now since tick no long fails, but when I equip the armor it doesnt show the attribute change.
    – Aceplante
    Commented Oct 25, 2021 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .