Run these from an operator’s chat, a command block, or a function file. Execute is simplified here — chain the rows in the order you want them to run.

How to Use the Item Command Generator

  1. Open the Item tab.
  2. Pick a mode – replace to put a new item in a slot, or modify to run an item modifier on an existing item.
  3. Pick target kind (block for a container at a position, entity for a player or mob) and enter the target.
  4. Enter the slot – for example hotbar.0, container.5, or weapon.mainhand.
  5. For replace, choose the item ID and optional count. For modify, enter the namespaced ID of an item modifier defined in a data pack.
  6. Copy the generated /item command into a command block, function, or an operator’s chat.

Command Syntax Reference

/item replace (block <pos>|entity <targets>) <slot> with <item> [<count>]
/item modify (block <pos>|entity <targets>) <slot> <modifier>

/item is the dedicated command for touching a single inventory slot without hand-writing NBT. The block/entity keyword before the target is mandatory – a container block needs a position (~ ~ ~, or absolute coordinates), while a player or mob needs a selector. Slot names follow Minecraft’s slot-id scheme: hotbar.0hotbar.8 for the hotbar, inventory.9inventory.35 for the main inventory, armor.head/chest/legs/feet, weapon.mainhand/weapon.offhand, and container.0 upward for chests and other block containers. replace ... with <item> [<count>] overwrites the slot outright – anything already there is gone. modify ... <modifier> instead runs a data-pack-defined item modifier function against whatever’s already in the slot, which can add enchantments, change count, or apply loot-table-style transformations without you specifying the resulting item directly.

Frequently Asked Questions

Why is block or entity mandatory before the target, instead of Minecraft guessing?

A position like ~ ~ ~ and a selector like @p aren’t always unambiguous to the parser, and block containers versus entity inventories use different slot-numbering ranges – so the command requires you to say explicitly which kind of target you mean before it even looks at what you typed there.

What slot do I use to replace a player’s held item or armor?

The main hand is weapon.mainhand and the off hand is weapon.offhand. Armor pieces are armor.head, armor.chest, armor.legs, and armor.feet. The regular hotbar and inventory use numbered slots (hotbar.0 through hotbar.8, inventory.9 through inventory.35).

What is an item modifier, and where do I define one?

An item modifier is a small JSON function, stored in a data pack under item_modifiers, that transforms an existing item stack – things like adding an enchantment, setting a custom name, or changing its count based on a formula. /item modify is how you apply one of those pre-defined modifiers to whatever’s currently sitting in a slot, referenced by its namespaced ID like mynamespace:my_modifier.

Does /item replace stack with whatever’s already in the slot, or overwrite it?

It overwrites completely – whatever item and count were previously in that slot are discarded and replaced by the new item and count you specify. If you need to combine with an existing stack instead of replacing it, that’s a job for a data-pack loot function or /data modify, not /item replace.

Can I use /item replace to fill a chest slot from a distance?

Yes – with block <pos> as the target kind, you can target any loaded container at any position, not just one you’re standing next to, so a command block or function can restock a chest’s container.N slot from anywhere in the loaded world.

Related Tools