
Command reference
Item Components
Items in commands are written as an id followed by components in square brackets. Components hold everything special about an item, such as its name, enchantments and durability.
| Item syntax | id[component=value,component=value]. The minecraft: part of ids and component names may be left out. |
| Removing a component | Put ! before the name with no value, for example minecraft:diamond_sword[!attribute_modifiers]. |
| Repeating | Each component may appear only once per item. |
| Values | Written in the data format: numbers, quoted text, lists in [ ] and named values in { }. |
| Component types | 119 that can be used in commands. |
| Item tests | Used by /clear and /execute if items. Start with an item id, an item tag with #, or * for any item, then optional tests in [ ]. |
| Combining tests | A comma means both tests must pass, | means either may pass, ! before a test reverses it. |
| Exact test | component=value passes when the item has exactly that value. |
| Partial test | name~value checks part of a component. Available for attribute_modifiers, bundle_contents, container, custom_data, damage, enchantments, firework_explosion, fireworks, jukebox_playable, potion_contents, stored_enchantments, trim, villager/variant, writable_book_content and written_book_content. |
| Count test | count=5 for an exact stack size, or count~{min:..,max:..} for a range. |
| Where data in braces still applies | Entity and block data: /summon, /data, the nbt selector argument and block data after a block id. |
| enchantments | Enchantments on the item with their levels | /give @s minecraft:diamond_sword[enchantments={sharpness:5,unbreaking:3}] |
| stored_enchantments | Enchantments held by an enchanted book | /give @s minecraft:enchanted_book[stored_enchantments={mending:1}] |
| custom_name | Name shown for the item, as a text component | /give @s minecraft:stick[custom_name={text:"Magic Wand",color:"gold",italic:false}] |
| item_name | Base name of the item, as a text component | /give @s minecraft:stick[item_name="Wand"] |
| lore | Extra tooltip lines, a list of text components | /give @s minecraft:stick[lore=["First line",{text:"Second line",color:"gray"}]] |
| damage | Durability already used up | /give @s minecraft:diamond_pickaxe[damage=100] |
| max_damage | Total durability | /give @s minecraft:diamond_pickaxe[max_damage=5000] |
| unbreakable | Item never loses durability | /give @s minecraft:diamond_pickaxe[unbreakable={}] |
| max_stack_size | Largest stack, 1 to 99 | /give @s minecraft:ender_pearl[max_stack_size=64] |
| attribute_modifiers | Attribute changes while the item is in a slot | /give @s minecraft:stick[attribute_modifiers=[{type:"minecraft:attack_damage",amount:10,id:"example:bonus",operation:"add_value",slot:"mainhand"}]] |
| potion_contents | Potion type, color and custom effects | /give @s minecraft:potion[potion_contents={custom_color:16711680,custom_effects:[{id:"minecraft:speed",amplifier:1,duration:600}]}] |
| dyed_color | Dye color as one number or as [red,green,blue] from 0 to 1 | /give @s minecraft:leather_chestplate[dyed_color=16711680] |
| fireworks | Flight time and explosions of a rocket | /give @s minecraft:firework_rocket[fireworks={flight_duration:2,explosions:[{shape:"large_ball",colors:[I;16711680],fade_colors:[I;255],has_trail:true,has_twinkle:true}]}] |
| firework_explosion | Explosion of a firework star | /give @s minecraft:firework_star[firework_explosion={shape:"star",colors:[I;65280]}] |
| written_book_content | Title, author and pages of a written book | /give @s minecraft:written_book[written_book_content={title:"Guide",author:"Steve",pages:["Page one",{text:"Page two",bold:true}]}] |
| writable_book_content | Pages of a book and quill | /give @s minecraft:writable_book[writable_book_content={pages:["Notes"]}] |
| food | Hunger and saturation restored when eaten | /give @s minecraft:stick[food={nutrition:4,saturation:2.4,can_always_eat:true},consumable={}] |
| consumable | Makes the item usable by eating or drinking | /give @s minecraft:stick[consumable={consume_seconds:0.8,animation:"eat"}] |
| tooltip_display | Hides the tooltip or single components in it | /give @s minecraft:diamond_sword[enchantments={sharpness:5},tooltip_display={hidden_components:["minecraft:enchantments"]}] |
| enchantment_glint_override | Forces the enchantment shine on or off | /give @s minecraft:stick[enchantment_glint_override=true] |
| rarity | Name color class: common, uncommon, rare or epic | /give @s minecraft:stick[rarity="epic"] |
| custom_data | Free data for data packs | /give @s minecraft:stick[custom_data={quest_item:1b}] |
| custom_model_data | Values that resource packs use to pick a model | /give @s minecraft:stick[custom_model_data={floats:[1.0f],strings:["wand"]}] |
| item_model | Model used to draw the item | /give @s minecraft:stick[item_model="minecraft:blaze_rod"] |
| can_break | Blocks the item can break in Adventure mode | /give @s minecraft:diamond_pickaxe[can_break={blocks:"#minecraft:logs"}] |
| can_place_on | Blocks the item can be placed on in Adventure mode | /give @s minecraft:stone[can_place_on={blocks:"minecraft:grass_block"}] |
| container | Items stored inside a container item | /give @s minecraft:chest[container=[{slot:0,item:{id:"minecraft:diamond",count:3}}]] |
| bundle_contents | Items inside a bundle | /give @s minecraft:bundle[bundle_contents=[{id:"minecraft:arrow",count:16}]] |
| profile | Player whose skin a player head shows | /give @s minecraft:player_head[profile={name:"Notch"}] |
| trim | Armor trim material and pattern | /give @s minecraft:iron_chestplate[trim={material:"minecraft:gold",pattern:"minecraft:coast"}] |
| equippable | Lets the item be worn in a slot | /give @s minecraft:stick[equippable={slot:"head"}] |
| use_cooldown | Wait time in seconds after use | /give @s minecraft:ender_pearl[use_cooldown={seconds:5}] |
| repair_cost | Extra anvil cost in levels | /give @s minecraft:diamond_sword[repair_cost=10] |
| block_entity_data | Block data applied when the block is placed | /give @s minecraft:spawner[block_entity_data={id:"minecraft:mob_spawner",Delay:20s}] |
| entity_data | Entity data applied when the item creates an entity | /give @s minecraft:armor_stand[entity_data={id:"minecraft:armor_stand",Small:1b}] |
| id | That item | /clear @s minecraft:diamond |
| #tag | Any item in the tag | /clear @s #minecraft:planks |
| * | Any item | /clear @s * |
| [component] | Items that have the component | /clear @s *[damage] |
| [!component] | Items that do not have the component | /clear @s *[!damage] |
| [component=value] | Items whose component is exactly the value | /clear @s minecraft:diamond_sword[damage=0] |
| [name~value] | Items that pass a partial test | /clear @s *[enchantments~[{enchantments:"minecraft:sharpness",levels:{min:3}}]] |
| [count=n] | Stacks of exactly that size | /clear @s minecraft:stick[count=5] |
| [count~{min:n}] | Stacks in a size range | /clear @s *[count~{min:32}] |
| [a|b] | Items that pass either test | /clear @s *[damage|unbreakable] |
| [a,b] | Items that pass both tests | /clear @s #minecraft:swords[enchantments~[{}],!custom_name] |
| Byte | Whole number with b | 1b |
| Short | Whole number with s | 20s |
| Integer | Whole number, or with i | 5 |
| Long | Whole number with L | 4L |
| Float | Number with f | 5.5f |
| Double | Number with a decimal point, or with d | 6.5d |
| True or false | true or false, stored as 1b or 0b | true |
| Text | In double or single quotes. Simple words need no quotes | "Steve" |
| List | Values in [ ] separated by commas | [1,2,3] |
| Named values | key:value pairs in { } | {id:"minecraft:diamond",count:3} |
| Byte list | [B; ...] | [B;1b,2b] |
| Integer list | [I; ...] | [I;1,2] |
| Long list | [L; ...] | [L;1L,2L] |
| Hex or binary number | 0x or 0b in front | 0x1F |
| Unsigned or signed | u or s before the type letter | 255ub |
| Digit grouping | Underscores between digits | 1_000 |
| bool(...) | Turns a number into true or false | bool(1) |
| uuid(...) | Turns a UUID text into its stored form | uuid("dd12be42-52a9-4a91-a8a1-11c01849e498") |
| Entity data on summon | /summon minecraft:pig ~ ~ ~ {NoAI:1b} |
| Changing entity data | /data merge entity @n[type=minecraft:zombie] {NoAI:1b,CustomName:"Bob"} |
| Reading with a data path | /data get entity @s Inventory[{id:"minecraft:diamond"}].count |
| Component inside a data path | /data get entity @s SelectedItem.components."minecraft:damage" |
| Block data | /data get block ~ ~ ~ Items[0] |
| Command storage | /data modify storage my_pack:data name set value "Steve" |
| Selector filter | /kill @e[type=minecraft:zombie,nbt={NoAI:1b}] |
/give @s minecraft:diamond_sword[custom_name={text:"Excalibur",color:"gold",italic:false},enchantments={sharpness:5},unbreakable={}]Gives an unbreakable Sharpness V sword with a gold name.
/give @s minecraft:diamond_sword[!attribute_modifiers]Gives a diamond sword without its attack damage and speed bonuses.
/give @s minecraft:potion[potion_contents={potion:"minecraft:strong_healing"}]Gives a Potion of Healing II.
/item replace entity @s weapon.mainhand with minecraft:diamond_sword[enchantments={sharpness:5}]Puts a Sharpness V diamond sword in your main hand.
/clear @s *[damage~{durability:{max:10}}]Removes every item with 10 or less durability left.
/execute if items entity @s weapon.mainhand minecraft:diamond_sword run say yesSays yes if you hold a diamond sword.
/execute if items entity @s container.* *[custom_data~{key:1b}] run say yesSays yes if any inventory slot holds an item whose custom data has key set to 1b.
/data merge storage my_pack:data {a:1,b:2b,c:3s,d:4L,e:5.5f,f:6.5d,g:"text",h:[1,2,3],i:[B;1b,2b],j:[I;1,2],k:[L;1L,2L],l:{m:true}}Stores one value of each data type.

