mojira.dev
MC-349

Villagers ignore data tags in trading

Re-opening applies specifically to data tags such as having a custom name

Villagers will only check an item's ID, not its damage value or any other data, in determining whether they will accept it. This leads to interesting situations where a priest will fully restore an item's durability when enchanting it, and a modified villager requesting bonemeal will just as easily accept ink sacs.

This bug also prevents map makers from designating custom items for villager trade (e.g. a piece of glowstone with a custom name and enchantment will be treated the same as an ordinary piece of glowstone).

What I expected to happen was...:
The villager would only accept the item if it was the same as the item they request - not if it merely shared the same data value.

What actually happened was...:
Priests would accept damaged tools and fully restore them when enchanting them. Modified wool-buyers were colorblind. Names and enchantments on items were ignored.

Steps to Reproduce:
1. Find a priest with an offer to enchant an item. Enchantment offers are rarer than other offers, so this can take some time/spawning.
2. Attempt to enchant a badly damaged tool using this priest.
3. Observe that the item has been enchanted, and has also been restored to its maximum durability.

3b. If you attempt to enchant a previously enchanted item with this priest, you will observe that the old enchantment is ignored and the new one is placed. However, normally it is not possible to unenchant an item, and even anvils will charge extra for overwritten enchantments, so this behavior is not consistent.

Caveat to fixing:
Although making trades strict would fix the issues outlined above, it would cause other issues. Farmers would then only accept white wool, and it would be impossible to fulfill a librarian's request for a Written Book.

Instead, it may be preferable (if anything is done about this issue at all) to add a new tag to an offer, determining whether it is to be considered strict. Thus, among vanilla Minecraft offers, the priest's enchantment offers would be marked 'strict', requiring unenchanted items at full durability. As this would be an NBT tag, map-makers would also be able to make use of it to prevent the aforementioned issues in custom traders.

Linked issues

Comments 33

In terms of consistency, I agree that adding enchantments to items should not affect their durability. However, seeing as different colours of wool are not distinguished in terms of, say, crafting, it doesn't really make sense for villagers to make this distinction.

Yes, this is why I suggested the fix should only apply to priest's enchantments, and to whatever custom offers a map maker chooses to add the property to. I explicitly said that it would be an issue if farmers distinguished wool color 😛

Jesper the End

confirmed, NBT tags, I understand why villagers don't look at that.
Damage values too a bit, when we're talking about tools. Although when you make a custom villager, it would be handy to trade only with a certain map.

That is a bad glitch in my opinion. You can forever repair your diamond tools at almost no cost. Enchanting damaged tools should at least retain the damage value.

Jesper the End

I'll go with 'only the green villager watches NBT data and damage values' that's handy for mapmakers.

23 more comments

In the 1.8 update, it seems this might have been partially fixed, probably because they went through and rebalanced villager trading. For the modified trades, the commands might not have been set up properly.
{Offers:{Recipes:[0:{buy:{id:"minecraft:Item name",Damage:0s,Count:1b}
,sell{id:"minecraft:Item name",Damage:0s,Count:1b,
tag:{ench:[0:{id:1s,lvl:1s},]}}},]}}
Mapmakers can easily set up villager trading using this data tag set up; tag:{ench:}} is optional.
Villagers will only accept the specified data values, so items like dyes and wool will work as intended now.

entitydata @e[type=Villager] {Offers:{Recipes:[0:{sell:{id:"minecraft:wool",Damage:14s,Count:1b,tag:{}},buy:{id:"minecraft:wool",Damage:0s,Count:1b},buyB:{id:"minecraft:dye",Damage:1s,Count:1b}},]}}

This command will make a villager accept regular white wool and red dye and trade you red wool. It will not accept any other wool or dye color.

Try using the command:
/entitydata @e[type=Villager,r=5] {Offers:{Recipes:[0:{sell:{id:"minecraft:diamond_pickaxe",Damage:0s,Count:1b,tag:{ench:[0:{id:35s,lvl:5s},]}},buy:{id:"minecraft:diamond_pickaxe",Damage:0s,Count:1b},buyB:{id:"minecraft:emerald",Damage:0s,Count:10b}},]}}

If I typed it correctly, this should change any villager within a radius of 5 blocks to offer the trade of a special diamond pickaxe with a fortune 5 enchant for a regular diamond pickaxe and 10 emerald. Unfortunately, this requires a fully repaired diamond pickaxe to work; trying to trade a damaged one will fail to work. If you wanted to have it not repair the pickaxe, you would have to change the value for the Damage tag under sell and buy so that they match.

For an easier solution, there would have to be a way where it checks the damage value on the tool being bought by the villager and apply that value to the tool being sold.
The problem is that these data tags apply to the items seen under the trading gui, and it simply checks for a match on your item and applies the values under the sell tag to the item being given to you. It would have to apply the damage value of your item to the item being sold, and take the values under the tag data tag from the sell tag, and merge that with the data of your item.

Sorry for the long explanation, but I hope this helps.

@Aaron, the problems is the inability to define the "tag" tag in the "buy" compound to force players to provide an item that has specific extra data, such as a display name or custom data. The "Damage" value detection was originally the issue, but was fixed a while ago in the 1.8 snapshots. The report remains open for the "tag" tag, specifically for the "buy" tag. The "sell" tag has always worked as far as I can recall.

Sorry, I just tested that and you are right. Thank you for the input, I have only recently started trying to help on bugs/glitchs and have also only started testing them, so I don't know exactly when these fixes were implemented.

It only applies the data under the tag data tag to the item under the trading gui.
The code is probably just missing for checking for a complete match, and it might be a simple fix.

The only fix for it repairing an item that gets enchanted by a villager seems to be that they just changed it to giving you an enchanted item for emeralds instead of enchanting an item you give them.

Aaron PLEASE stop editing your comments after you post, re-read them carefully before you submit your posts. Every time you edit them it sends everyone watching this Bug which is 30 people.

So far I have gotten 20+ emails of you editing the post you made, this is pretty irritating.

Thank you.

WolfieMario

michael

Confirmed

Minecraft 1.4.2, Minecraft 1.4.6, Minecraft 1.4.7, Snapshot 13w01a, Snapshot 13w01b, ..., Minecraft 14w30b, Minecraft 14w30c, Minecraft 14w31a, Minecraft 1.8-pre3, Minecraft 1.8

Minecraft 14w02a, Minecraft 1.8.1-pre4

Retrieved