mojira.dev
MC-749

Villager can have all trades disabled

The bug

Villagers can get into a state where all there trades are locked.

Cases

Unloading villager during refresh

This bug happens when you unload the villager before it refreshed its trades.

How to reproduce
  1. Spawn a villager

  2. Get all items it wants for its first trades in your inventory. It is easier if you are in Creative to be able to clone items if you need more.

  3. Start trading with the villager

  4. Without closing the GUI use all trades until they are disabled

  5. Close the GUI and directly afterwards close the world

  6. Load the world again
    → The trades will still be disabled and won't be enabled again

In some cases, such as when trading with Leather Workers or other villagers with low numbers of total trades, it is possible to skip steps 5 and 6 as those villagers can have all trades become locked without closing the world.

Code analysis

Based on 1.11.2 decompiled using MCP 9.35 rc1

The fields net.minecraft.entity.passive.EntityVillager.timeUntilReset and net.minecraft.entity.passive.EntityVillager.needsInitilization are not saved to NBT.

Suggested fix

See this comment.

Trade not being used for the first time and having bad luck

Based on 1.11.2 decompiled using MCP 9.35 rc1

As of 1.11.2 (and earlier versions) the method net.minecraft.entity.passive.EntityVillager.useRecipe(MerchantRecipe) only enables all disabled trades if a trade was used for the first time or with a one fifth chance. This means if you have bad luck, you can end up with all trades locked as well.

It is not known if this is intended or if the developers just did not want that trading any trade always enables all disabled trades, but forgot that it might happen that all trades get disabled.

Fix for affected villagers

This comment describes a fix for already affected villagers in case it is not intended that villagers with only disabled trades exist.

Remark: Consider adventure maps, where sometimes all trades are intentionally locked. Unlocking them when loading the villager might break the map, because players can get item they shouldn't have.

Linked issues

Attachments

Comments 108

This is a GUI issue.

"This is a GUI issue."

Why? Doesn't seem like a GUI issue to me-- or at least not only a GUI issue.

From MinecraftWiki: Villagers will remove offers if the offer has been used some number of times and it is not the villager's only offer. http://www.minecraftwiki.net/wiki/Trading

Is that what's going on here? Do you think that's what's happening but the GUI is indeed failing to update?

It is supposed to only allow a certain number of trades, which is slightly random. However for some reason the X won't appear, but the trade does stop. Closing and opening should show the X, no?

My apologies. I was using an altered texture pack, i though i had everything updated to 1.4.x, but apparently i missed the X.

My understanding was that you could trade as much of an item as you wanted as long as you don't leave the trading screen. I.E. that a trade was only removed once you leave the trading GUI. This is apparently no longer the case.

But there is still the issue that "removed" trades stay in the GUI – even sometimes if there are no other trade options.

I will update my bug report.

98 more comments

This bug can't be properly tested in 19w11a, because trade unlocking has changed. I don't know how exactly, but I've just traded 4 times normally and it locked everything in the villager UI. This report should probably be marked as blocked by some other report, but I don't know which one.

Quite possibly this issue has now become completely invalidated with the new trading system. No locked trades are unlocked anymore with normal trading (I believe), they get unlocked when the villager restocks by doing their jobs, so the problem is more obvious (however, intended according to the blog).

I will close this as fixed since with the new trading system the villagers will restock.

eleazzaar

Jeremy

Agnes Larsson

Confirmed

trading, villager

Minecraft 1.4.2, Minecraft 1.4.6, Minecraft 1.4.7, Snapshot 13w07a, Snapshot 13w09a, ..., Minecraft 19w05a, Minecraft 19w06a, Minecraft 19w07a, Minecraft 19w08b, Minecraft 19w09a

Minecraft 14w06a, Minecraft 19w11a

Retrieved