One interesting use of entity data tags is the ability to customize villagers in Minecraft. Villagers are mobs that can trade items with players, and their trading options are usually generated randomly. However, by customizing a villager with data tags, you can specify exactly what the villager wants to buy and sell.
For example, you can make a villager trade an emerald for a diamond, red wool for blue wool, gold nuggets for enchanted armor, a wooden sword and a stone sword for an iron sword, and so on.
This is useful for creating shopkeepers with very specific settings, such as a villager who accepts lapis lazuli in different quantities in exchange for weapons and potions. You can give villagers as many trading options as you want, and they can trade absolutely any item you want.
The tag is written this way:
{Offers: { Recipes: [ <recipe1> <recipe2> ... <last recipe> ] } }
Each recipe is a compound that can contain the following tags:
buy: An item compound representing the item that the villager wants to buy.
buyB: An item compound representing another item that the villager wants to buy. (Villagers sometimes want two different items in exchange for their wares.)
maxUses: The maximum number of times the trade can be used. This can be set to an extremely large number if you want the trade to be nearly infinitely available.
rewardExp: Equal to 1 (by default) if you gain experience points by using this trade. Otherwise, equal to 0.
sell: An item compound representing the item that the villager wants to sell.
uses: The number of times the trade has been used. This defaults to 0, so you generally can keep it as is.
Thus, for example, you could program a villager by entering the following command:
summon Villager ~ ~ ~ {Offers:{Recipes:[{ buy:{id:diamond,Count:50}, sell:{id:diamond_sword,tag:{ench:[{id:16, lvl:6}]}} },{ buy:{id:planks},buyB:{id:emerald}, sell:{id:iron_block},maxUses:999999, rewardExp:0} ]}}
This command creates a villager with two different offers:
The first trade allows you to spend 50 diamonds (buy:{id:diamond,Count:50}) in exchange for a diamond sword with the Sharpness VI enchantment.(sell:{id:diamond_sword,tag:{ench:[{id:16,lvl:6}]}})
The second trade allows you to spend wooden planks and an emerald (buy:{id:planks},buyB:{id:emerald}) in exchange for an iron block (sell:{id:iron_block}), but does not grant experience points (rewardExp:0) — this trade also almost never expires, because it can be used 999999 times (maxUses:999999).