3

I have made villagers before using MC Stacker. Here is my dilemma: I want to have the villager buy a golden sword with Looting II on it and sell a written book. I have set that up but the villager will not seem to buy the sword; the NBT tags are different. The swords are not the same despite the enchantments being the same.

Villager buys Pigman dropped

The villager will not trade since the NBT tags are different. How do I go about making them the same?

This is the command I used to summon the Villager:

/summon Villager ~ ~1 ~ {CustomName:"Kunueme",CustomNameVisible:1,Profession:1,Career:0,CareerLevel:18,O‌​ffers:{Recipes:[{rewardExp:0b,maxUses:2147483647,uses:0,buy:{id:golden_sword,Coun‌​t:1,tag:{ench:[{id:21,lvl:2}]}},sell:{id:written_book,Count:1,tag:{display:{Name:‌​"A buck"},title:"",author:"The Street",generation:0,pages:["{text:\"\",color:black}"]}}}]}}
  • Can you provide all the relevant commands used, from creating the villager to obtaining the sword? – Skylinerw Mar 16 '16 at 19:35
  • This is the command: /summon Villager ~ ~1 ~ {CustomName:"Kunueme",CustomNameVisible:1,Profession:1,Career:0,CareerLevel:18,Offers:{Recipes:[{rewardExp:0b,maxUses:2147483647,uses:0,buy:{id:golden_sword,Count:1,tag:{ench:[{id:21,lvl:2}]}},sell:{id:written_book,Count:1,tag:{display:{Name:"A buck"},title:"",author:"The Street",generation:0,pages:["{text:\"\",color:black}"]}}}]}} – Vethor Mar 16 '16 at 21:12
  • The sword is a regular loot drop from a Pigman? Or is it some sort of special pigman? – MrLemon Mar 16 '16 at 21:15
  • Just a regular pigman drop – Vethor Mar 17 '16 at 1:41
2

Your villager's ench tag contains id and lvl declared as Integers, while through normal means (enchanting, loot from pigmen) they would instead be Shorts. When matching NBT data, you must match even the datatypes. To declare a Short, you must append the numerical value with an "s".

/summon Villager ~ ~1 ~ {CustomName:"Kunueme",CustomNameVisible:1,Profession:1,Career:0,CareerLevel:18,Offers:{Recipes:[{rewardExp:0b,maxUses:2147483647,uses:0,buy:{id:golden_sword,Count:1,tag:{ench:[{id:21s,lvl:2s}]}},sell:{id:written_book,Count:1,tag:{display:{Name:"A buck"},title:"",author:"The Street",generation:0,pages:["{text:\"\",color:black}"]}}}]}}

Something to keep in mind is that NBT matching for villager trades differs from NBT matching through various commands (such as /scoreboard). For commands, List tag matching (that which encases data in square brackets) is lenient, in that the data you look for is scanned throughout the entire target's list. However, villager trading itself uses strict List detection, in that the list you specify must match exactly as the target item has it specified.

For example, testing for data:["a"] on an entity that contains data:["a","b"] will work fine, since "a" appears somewhere within the target.

If a villager trade looks for ench:[{id:21s,lvl:2s}] on an item that contains ench:[{id:21s,lvl:2s},{id:16s,lvl:1s}], it will not match because the lists are not exactly equal.

Villager trading is the only case as of 1.9 where List matching is strict. All other NBT matching will work fine. For example, if the item you're trading has a string tag that is not specified in the trade, the villager will still accept it and it will not conflict with trading.

  • This fixed it, However if the order of the enchantments is not the same as the vendors the villager will not buy it. I will just have to set all the orders for each set of enchants to be able to buy each sword. That's going to be a heck of a list ;) – Vethor Mar 17 '16 at 0:32
0

It looks like there's a tag on the sword in your inventory that's not on the sword the villager wants. Try throwing your sword on the ground and running /entitydata @e[type=Item,r=3]. Look in the error message for the Item:{} tag, and edit your villager command accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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