Wandering Trader

The wandering trader is a villager-like passive NPC mob found randomly across the world.

Spawning
The wandering trader appears randomly across the world or periodically in village gathering sites, usually near village meeting points, with one to two leashed trader llamas.

At any time, there can be only one wandering trader naturally spawned in the world.

After 24000 ticks (20 real-life minutes) have passed since the world is created, the game will start to attempt spawning a wandering trader. If there are no wandering traders currently in the world, 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 that one will spawn; if it fails, after another 24000 ticks another spawn attempt will be made with a 5% chance of success. If that fails, for all subsequent spawn attempts the chance will cap at 7.5%. After 48000 or 72000 ticks the trader will despawn and reset the cycle, leaving the llamas behind.

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

Behavior
The wandering trader has six random trades in Java Edition, or four in Bedrock Edition. New trades are not unlocked after trading with it.

After spawning, the wandering trader will have a managed schedule for 40–60 minutes. After the time expires, the wandering trader will despawn. They will despawn even if they are named with a name tag or put in a vehicle such as a minecart or boat. A wandering trader will despawn sooner if all trades have been locked.

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

Wandering traders will drink a potion of invisibility during dusk. Once it is dawn, they will drink milk to remove the invisibility.

Wandering traders will avoid zombies and their variants, all illager variants, and vexes, staying at least 8 blocks away.

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

Drops
When killed, the wandering trader will unleash its trader llamas. The leads will break and appear at the position of the llamas.

Wandering traders have a small chance of dropping a bucket of milk or a potion of invisibility if holding either and killed before they can finish drinking. The chances of them dropping either is increased with the Looting enchantment.

Trading
The trading system is a gameplay mechanic that allows players to trade emeralds for items and vice-versa. Their trades can be considered good or bad, depending on what the cost is and what items the player might get.

Right-clicking a wandering trader will allow a player to trade with them. Different offers may be viewed by pressing the left and right buttons next to the currently displayed offer. All offers involve emerald as a currency. Trading allows the acquisition of rare items that would otherwise be fairly difficult to obtain, such as coral or blue ice.

In Java Edition, after 2–12 times an offer is repeated, the wandering trader will lock the trade offer, and the wandering trader will no longer offer this trade permanently.

Unlike villagers who both give and receive emeralds in exchange for items, wandering traders only sell items for emeralds. Players cannot exchange items for emeralds. Wandering traders also have no experience bar and they don't modify their offers based on increased demand.

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