Trading



The trading system is a gameplay mechanic that allows players to trade emeralds for items (and vice-versa) with NPC villagers.

Information
Right-clicking a villager will allow a player to trade with them. Villagers will make offers based on their profession, and will only make trades based on whatever offers they are making. Different offers may be viewed by pressing the left and right buttons next to the currently displayed offer. Most offers involve emerald as a currency, and some item pertinent to the villager's profession. Trading can be very useful as it can allow you to acquire rare/uncommon items with little exploration and/or mining.

A villager will never offer to buy/sell the same item at different prices or quantities (for example, no villager will offer to buy either 16 raw pork or 17 raw pork: there can only be one offer to buy raw pork). However, the quantities and prices may vary from villager to villager, and a villager's own quantities/prices may change when they generate new offers.

All villagers initially have only one offer to make. They can generate new offers when the last offer available (rightmost on their list of offers) has been traded at least once. Note that the trading GUI must be closed before a villager will generate a new offer. When they do, they become surrounded with purple particles for a moment. New offers may involve items a villager was already buying/selling: in this case, the newly generated offer will overwrite the previous one, allowing a villager's prices (or priest's enchantments) to change. Although there is no maximum limit on the number of offers an individual villager can make, they can only have one offer per each item they can trade. In addition, when a villager already has many offers, there is a high probability that a newly generated offer will be of an item they already offer: thus the old offer will be overwritten, and there will not be any new offer slot added to the villager.

Right clicking on a villager pauses that villager's pathfinding and opens up the trading window.

Charcoal can be sold as coal to blacksmiths and butchers.

You cannot trade with child villagers.

Villagers will remove offers if the offer has been used some number of times and it is not the villager's only offer. The chance of an offer's removal is random, but an offer must be used at least 3 times before it is eligible for removal. After an offer has been used 13 times, it is guaranteed to be removed if you close the interface after trading it (this is true even if all 13 trades have been done at once).

It is possible to trade more than 13 times on a single offer because offers are never removed until the trading interface is closed, so you may buy an offer as many times as you can afford with one inventory. Furthermore, only one offer can be removed after the trading interface is closed: if you trade multiple offers beyond the limit, only the last one traded will be removed. In this way, an offer with more than 13 uses can be kept, and the game does not check offers for removal until the offer is traded.

In addition, if an offer is the last offer available, it is never removed even if its uses exceed 12. Once it is no longer the last offer, of course, it is eligible for removal.

When an offer is removed, it has the same particle effect as an offer being created.

Possible offers


The following table lists the minimum and maximum offers that a villager will make when buying and selling items.

Villager (green clothes)
''Note: The green Villager is only obtainable using server commands or mods. It does not spawn naturally, even when using a spawn egg, but in 12w26a, using third-party software, can be spawned from monster spawner.''

History
Before the Adventure Update, Notch once answered some questions about an idea he had, NPC Villages, where he revealed some thoughts about them:
 * If you treat the villagers well (giving them items), they'll give you items back.
 * If you treat the villagers badly (attacking/killing them), they'll try to do the same to you (feature added with Iron Golems).
 * Raiding chests will anger the owners of the town/chest and they will attack.

On May 21, 2012, Jeb released a screenshot of himself testing the Trading System. The image shows a GUI with buying and selling areas. The bottom area allows the player to sell various items for currency, whereas the top area uses this currency to purchase items. A possible way to buy them would be to put these currencies in the left slot, where the chicken is, and you can scroll through items for the right slot to take the item you choose once you click on it. The player may use the arrow buttons to scroll through a villager's inventory and select the desired item. Jeb also mentioned that this may be an end to non-renewable resources, supposedly as most can be bought for some price from NPCs. In the image, a red currency item can be seen that was later revealed in snapshot 12w21a as a ruby item that was changed to emerald before 12w21a, for reasons unknown.

An ore block can be seen in the background which was later revealed in snapshot 12w21a to be Ruby Ore, which was changed to emerald ore before 12w21a for reasons unknown.

Another image released earlier by Jeb shows separated villagers. This tweet also says "this is how I experiment with villagers". With spawn eggs for spawning random villagers, one would think that by keeping them separate Jeb was testing each profession of the villagers, perhaps because they each trade different items or would be.

With the implementation of the trading system, most or all resources become "renewable" since nonrenewable resources can be traded from villagers.

As of snapshot 12w22a, Priests no longer offer to buy Rotten Flesh or Eyes of Ender. Eyes of Ender are now sold by priests, and rotten flesh is not a trade at all.

The trading UI has been changed where an extra input space has been added where tools can be placed for buying enchantments and/or repair.

Prior to snapshot 12w23a, the probability of a librarian buying a written book as a potential offer was 1.3 (130%), meaning it would always be a potential offer. This meant it was impossible for librarians to offer to buy gold ingots, as this is a default offer which occurs if no offers are put on the list of potential offers. This has been corrected in snapshot 12w23a.

Bugs

 * Priests enchanting items ignore durability, repairing the item in the process (may not be a bug).
 * Farmers may be meant to sell arrows in quantities of 6-19, rather than just 5. However, the quantity range is backwards in the code, resulting in only 5 as a possible offer.

Trivia

 * Right-clicking on a villager right after a killing blow is dealt will result in the player trading with a dead villager. The trade goes through without any problems.
 * Trading is currently the only legitimate way to get Chainmail Armor as well as Bottles O' Enchanting without creative mode.
 * Gold Ingots are used as a fallback offer; any time a villager randomly selects none of its offers, it chooses to buy gold ingots instead. This is why gold is offered so rarely as a trade, and also why it is the green villager's only item.
 * If you're not satisfied with the current trade offers, you can kill some of the villagers with lava. The remaining villagers will start breeding again, resulting in possibly better offers. Killing them with lava will not make the Iron Golem hostile.