Ok, I've been using a command block to spawn a villager that has custom trades. There's no problem with that at all- I'm just wondering if it's possible to have a villager trade me an item that has a custom name (eg. Key). Or is this unchangeable, so I'd need to name it with an anvil after purchase?

/summon Villager ~ ~1 ~ {Offers:{Recipes:[{buy:{id:"minecraft:emerald",Count:4},sell:{id:"minecraft:leather_helmet",Count:1}},{buy:{id:"minecraft:emerald",Count:6},sell:{id:"minecraft:leather_chestplate",Count:1}},{buy:{id:"minecraft:emerald",Count:5},sell:{id:"minecraft:leather_leggings",Count:1}}]}}

The code is fully functional, it's just integrating custom names for the item he sells.


NBT you would include in /give commands for items goes inside the "tag" compound. https://minecraft.gamepedia.com/Player.dat_format#Item_structure

/summon Villager ~ ~1 ~ {Offers:{Recipes:[{buy:{id:"minecraft:emerald",Count:4b},sell:{id:"minecraft:leather_helmet",Count:1b,tag:{display:{Name:"Foo"}}}},{buy:{id:"minecraft:emerald",Count:6b},sell:{id:"minecraft:leather_chestplate",Count:1b}},{buy:{id:"minecraft:emerald",Count:5b},sell:{id:"minecraft:leather_leggings",Count:1b}}]}}
| improve this answer | |

You are wanting to add data that would require adding a data tag. Lets look at the first item sold:


The give command to give this item is:

/give @p minecraft:leather_chestplate 1

To add a name to the give command, the dataTag argument needs to be specified:

/give @p minecraft:leather_chestplate 1 0 {display:{Name:"The custom name"}}

In your command, everything contained within the sell compound is defining the item. This requires following the item structure, which means the data tag information has to be within a tag compound:

tag:{display:{Name:"The custom name"}}

This would give you a final sell compound of:

sell:{id:"minecraft:leather_chestplate",Count:1b,tag:{display:{Name:"The custom name"}}}

You can add the tag compound to any of the buy or sell compounds in your summon command.

You can also specify enchantments, attribute modifiers, flags, lore, etc. within the tag compound.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.