Villager Trade
Villager trades are the blueprints for actual trade offers generated by villagers and wandering traders. Java Edition only.
Definition Format
Registry VILLAGER_TRADE, data pack path villager_trade (files in data/<namespace>/villager_trade/; tags in tags/villager_trade/).
wants(required) — first bought item:id(item type), optionalcomponents(component checks on the bought item),count(default 1; base amount, number provider — see Pricing).additional_wants— second bought item (same format).gives(required) — the sold item (item template).given_item_modifiers— item modifiers on the sold item (inline only, no file references); if the final stack is empty, the trade won't generate an offer.max_uses(default 4, <1 → 1; floored) — max trades before the offer locks.reputation_discount(default 0, <0 → 0) — price multiplier (float).xp(default 1, <0 → 0; floored) — XP given after trading.merchant_predicate— loot predicate on the villager (inline only); failure → no offer.double_trade_price_enchantments— enchantment ID/list/tag: if the sold item'sstored_enchantmentscontains one, the bought extra amount doubles.
Generation uses the villager_trade loot context: this_entity (the villager), origin (the villager's feet position), additional_cost_component_allowed.
Behavior
Definitions load once at server startup (restart required). Trades are referenced by trade sets, which generate actual offers.
Pricing
The first bought item's count = base amount (from count) + extra amount (from the item's additional_trade_cost component, settable only by item modifiers):
enchant_with_levelswithinclude_additional_cost_component: truesets it to the enchanting level.enchant_randomlywith it true sets 2 + random(0, 5 + level×10) + 3×level (level = the enchantment's level).
After the item is modified the component is removed and its value becomes the extra amount; if the price-doubling check matches, the extra doubles. Final count = base + extra, clamped to [1, max stack size].