Minecraft Blogs / Tutorial

1.17 new /item command and item modifiers explained!

  • 18,938 views, 9 today
  • 14
  • 5
  • 7
One_Nose's Avatar One_Nose
Level 58 : Grandmaster Dragonborn Hero
1.17 brings an interesting addition for data packs that allows you to change and copy items easily. I will try to explain what these features are and how to use them.

Where is /replaceitem?

The new snapshot removed the command /replaceitem which allowed us to replace items in certain slots of entities and/or blocks. Well, not exaxctly. /replaceitem was replaced by a new command, far more powerful – /item.
Old syntax
/replaceitem (block <pos> | entity <targets>) <slot> <item> [<count>]
New syntax
/item replace (block <pos> | entity <targets>) <slot> with <item> [<count>]It's basically the same syntax, but if you look at the new syntax, you'll see we now need to declare we want to replace (between <slot> and <item>) – this is because /item can be more powerful than this. Note we also need to declare "with".

Copying items

The new command can copy items from one source to another. We could already do that using /data modify ... from but this doesn't work on players, which we usually like to work with, since /data cannot affect a player's data.
/item replace (block <pos> | entity <targets>) <slot> from (block <pos> | entity <targets>) <slot> [<modifier>]That's it. We can copy items from one source to another. Here is an example of copying the item in the main hand of all players into their off-hand.
Note: you might have noticed the [<modifier>] at the end. I will explain this later.
/execute as @a run item replace entity @s weapon.offhand from entity @s weapon.mainhandThis is something you couldn't have done before, since player's data is hard to modify. For the next and final syntax, we need to understand a new data pack feature – item modifiers (and no, it's not related to attributes).

Modifying existing items

If you ever used the loot tables feature of data packs, this feature will be familiar to you. Item modifiers are JSON files placed inside the new data/<namespace_folder>/item_modifiers directory, and each modifier contains a loot table function or a list of functions that explain how to modify an item. Basically you can teach Minecraft to change an item however you want and then use /item to do that. It's similar to /enchant which can modify an item to be enchanted, but is highly more powerful. If you want, you can use "minecraft:set_nbt" function to do basically whatever you want. The following item modifier changes an item's name to "Useless Stick".
"function": "set_name",
"name": "Useless Stick"
Let's say that we saved the file as "useless.json" under the namespace "whythisexists" and /reloaded. Now, if we hold anything and run the following its name would become "Useless Stick".
/item modify entity @s weapon.mainhand whythisexists:uselessWhich brings us to the last syntax:
/item modify (block <pos> | entity <target>) <slot> <modifier>We can also apply a modifier while copying an item, like putting in your off-hand a useless version of the item in your main hand:
/execute as @a run item replace entity @s weapon.offhand from entity @s weapon.mainhand whythisexists:uselessAnd that's all about the new /item command. Any feedback on the tutorial will be appreciated, and good luck with your new data pack.

Create an account or sign in to comment.

04/26/2022 2:40 pm
Level 48 : Master Engineer
Catfoolyou's Avatar
can this be used in a crafting recipe's result?
04/27/2022 8:49 am
He/Him • Level 58 : Grandmaster Dragonborn Hero
One_Nose's Avatar
No, it must be inside of a permanent inventory.
04/27/2022 3:10 pm
Level 48 : Master Engineer
Catfoolyou's Avatar
09/01/2021 7:49 am
Level 1 : New Miner
creeperkrazzy's Avatar
how can i modify the NBT of a specific item in any slot?
09/01/2021 12:58 pm
He/Him • Level 58 : Grandmaster Dragonborn Hero
One_Nose's Avatar
There is no easier answer than just copy-pasting the command for every slot.
05/30/2021 2:10 am
Level 36 : Artisan Soldier
Hazem-chan's Avatar
thanks very helpful
05/31/2021 3:26 am
He/Him • Level 58 : Grandmaster Dragonborn Hero
One_Nose's Avatar
Thank you. Note that the command syntax was changed since then. I updated this blog.
Planet Minecraft


© 2010 - 2024