Wandering Trader

The wandering trader is a passive mob found randomly across the world. It can trade, making natural items more available and in some cases, less dangerous to obtain.

Spawning
The wandering trader appears randomly across the world with 2 leashed trader llamas. $$, wandering traders periodically spawn in village gathering sites, usually near village meeting points.

At any time, there can be only one wandering trader naturally spawned in loaded chunks. After 24000 ticks (20 real-life minutes, or 1 Minecraft day) have passed since the world is created, the game attempts to spawn a wandering trader. If there are no wandering traders currently in any loaded chunks, the game tries to spawn a new wandering trader after every following 24000 ticks, within a 48-block radius of a player. The first spawn attempt has a 2.5% chance of success; if it fails, after another 24000 ticks another spawn attempt is made with a 5% chance of success. If that fails, for all subsequent spawn attempts the chance caps at 7.5%. On average, it takes 14.325 Minecraft days for a wandering trader to spawn. After 48000 or 72000 ticks, the trader despawns, even when named, along with its llamas, resetting the cycle.

Trader llamas do not despawn if they are detached from the wandering trader's leads.

$$, when using spawn eggs or the command to spawn a wandering trader, llamas always spawn with it. Wandering traders never spawn if   is set to false.

Behavior
The wandering trader has 6 random trades. New trades are not unlocked after trading with it.

After spawning, the wandering trader has a managed schedule for 40–60 minutes. After the time expires, the wandering trader despawns, even if the wandering trader is named with a name tag or put in a vehicle such as a minecart or boat. A wandering trader despawns sooner if all trades have been locked. The trader may later respawn with new trades.

The wandering trader can sometimes form a caravan, due to wild llamas that follow the leashed trader llama(s).

Wandering traders drink a potion of invisibility during dusk. At dawn they drink milk to remove the invisibility.

Wandering traders avoid zombies and their variants, all illager variants, and vexes, staying at least 8 blocks away. Unlike other villagers, a wandering trader killed by zombies does not become a zombie villager.

Wandering traders drink potions of invisibility if hurt by magic attacks or projectiles from hostile mobs, or when avoiding illagers, vexes, and zombies.

When attacked by a player, a wandering trader flees from the player as a villager would do. The llamas, however, attack the player if their master gets hit.

Like villagers, wandering traders can also close and open wooden doors.

Unlike most other villager-like mobs, wandering traders do not visually sit down when riding objects such as boats and minecarts, which is intentional.

Drops

 * a milk bucket (8.5% chance, increased 1% per level of Looting).
 * a potion of invisibility (8.5% chance, increased 1% per level of Looting) if killed while holding or before finishing drinking.

A wandering trader will also drop leads when killed or when separated too far from its trader llamas. The leads break and appear at the position of the llamas. The llamas also drop their leads when killed, and if a wandering trader and one of its llamas are riding the same boat, the lead breaks.

Trading
"A mysterious blue-clad villager has appeared out of nowhere! You gasp and drop your controller. You fall to your knees. Your mind explodes with questions: "How did it get here?", "Why is it trying to trade with me?" and "Minecraft villagers outside of villages? What blasphemy is this?!" Calm down, friend! Everything is fine! You've just encountered Minecraft's latest and most experienced salesman – the Wandering Trader!"

- Per Landin

The trading system is a gameplay mechanic that allows players to buy items with emeralds.

A player can click on the wandering trader to view the items offered for sale. Different offers are visible in a list, clicking on one of the offers will move the corresponding items involved in the offer to the slots above the player's inventory (if the player has said items). All offers involve emeralds as a currency. A wandering trader has an emerald above its head while trading and typically sells items generated in the world or otherwise related to nature, such as plants, dyes, and buckets of fish. They can also trade less common items, such as coral or blue ice.

After the player purchases the same item several times, the wandering trader locks the trade, but unlike villagers, never unlocks the trade.

Unlike villagers, Wandering Traders only sell items and do not buy them. Wandering Traders do not have an experience bar and do not modify their offers based on increased or decreased demand. This can be changed by the player by editing the corresponding NBT data flag through use of the data command.

Data values
Wandering traders have entity data associated with them that contain various properties of the mob.