This question already has an answer here:

I'm trying to create NPCs that allow individuals to upgrade their enchanted books beyond what is normally acquirable in survival mode. Basically the idea is that they can take two enchanted books of the same level and trade them for an enchanted book of the next level up.

(E.g. 2 enchanted books with unbreaking I in exchange for 1 enchanted book with unbreaking II)

The following code is the one I have been using to summon the villagers but there are a few issues that I have encountered.

/summon Villager ~ ~ ~ 

Firstly, I keep getting the "data tag parsing failed" error when trying to execute this command in chat. I'm assuming this is because it is too long to execute in chat since I do not have this issue when using a command block.

Secondly, after summoning the Villager with the command block, the interface is what I want, accepting two books for one. enter image description here

But when I put in the two unbreaking I books, I do not get the unbreaking II book out. It is as if the game detects the two books I have as different from the ones required by the Villager. enter image description here

Anyone can help me identify what is wrong with my code, or tell me if what I am trying to do is not possible.


marked as duplicate by user232393, galacticninja, Joachim, Reflexive, Lore Friendly Jul 14 at 4:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Try adding type indicators in the numeric tags. Writing to NBT works without them, but testing sometimes requires them. You can also throw out your enchanted books and run /entitydata @e[type=item,c=1] {} to get the exact NBT of the item. – Fabian Röling Dec 8 '17 at 6:45
  • @bearb001 You do realize that your edit to the question has the side effect of completing the Close Votes review and thus causing this clearly duplicate question to remain open. – pppery Jul 8 at 21:52
  • @pppery thank you for bringing this to my attention, I didn't know that would happen. – user232393 Jul 8 at 21:53
  • It isn't as obvious as duplicate to me, because it is used in very different ways. I'd be ok with closing it as a duplicate though, because it is quite similar. – user232393 Jul 8 at 21:56
  • @bearb001 Both questions are "my command syntax isn't working" questions, in which the reason the command not working is because the asker failed to specify the data types for tags that need data types. That seems clearly a duplicate to me. – pppery Jul 8 at 21:57

The command will not fit into chat, you are correct about that causing your error.

The reason the villager will not accept the books is because you are not specifying data type with the id and lvl. The villager is looking for a books with values that are stored as integers. Enchanted books values are stored as shorts when naturally generated so their values should be followed by s (id:34s).

Here is your command with correct data types:

summon Villager ~ ~ ~ {Offers:{Recipes:[{maxUses:1000,buy:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34s,lvl:1s}]}},buyB:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34s,lvl:1s}]}},sell:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34s,lvl:2s}]}}}]},Silent:1}

Which then accepts the books:

  • This works like a charm thanks! Just out of curiosity, is there a way to get around the length restriction in chat without a command block? Basically the server I am trying to do this on does not have command blocks enabled. – Zotius Dec 11 '17 at 2:18
  • I don't personally know of any way. I imagine there are mods/plugins that allow it but I have never looked into it. – IronAnvil Dec 11 '17 at 3:51

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