Villager trade definition

Minecraft Wiki article. Categories: Java_Edition_upcoming, Data_packs

📌 Mirrored from Minecraft Wiki

This article is reproduced from Villager trade definition on the Minecraft Wiki. Mirrored from revision 3690455. It is licensed CC BY-NC-SA 3.0 by the Minecraft Wiki contributors — not under the Codex’s CC BY-SA 4.0, and it may not be used commercially. Edits belong upstream, not here.

Villager trades are stored as JSON files within a data pack in the path data/<namespace>/villager_trade. Despite their name, they also control the trades of wandering traders.

JSON format

  • [NBT Compound / JSON Object]: The root object.
    • [NBT Compound / JSON Object] wants: The item needed for the trade (i.e. the price)
      • [String] id: The resource location of the item. Must not be minecraft:air
      • [Int][Float][NBT Compound / JSON Object] count: Optional number provider (defaults to 1). Define the cost, number of items needed for the trade. The final cost can be altered by the additional cost (by additional_trade_cost and [String][NBT List / JSON Array] double_trade_price_enchantments). If the cost quantity is less than 1, the trade is removed. Final cost above max_stack_size are treated as max_stack_size.
      • [NBT Compound / JSON Object] components: Optional map of additional (non-default) data components.
    • [NBT Compound / JSON Object] additional_wants: Secondary item needed for the trade, optional. No altered by the additional cost.
      • Same format as [NBT Compound / JSON Object] wants
    • [NBT Compound / JSON Object] gives: The item given by the trade
    • [NBT List / JSON Array] given_item_modifiers: Optional list of modifiers to apply to the item given by the trade
      • [NBT Compound / JSON Object]: An inline item modifier. The reference modifier is not supported.
    • [Int][Float][NBT Compound / JSON Object] max_uses: Optional number provider (defaults to 4) determining the maximum amount of uses of this trade. Values below 1 are treated as 1.
    • [Int][Float][NBT Compound / JSON Object] reputation_discount: Optional number provider (defaults to 0) determining how much reputation (such as discounts and penalties) affect the count of [NBT Compound / JSON Object] wants. Called 'price multiplier' in Trading § Sale prices. Values below 0 are treated as 0.
    • [Int][Float][NBT Compound / JSON Object] xp: Optional number provider (defaults to 1) determining how much xp the merchant gets when the trade is done. Values below 0 are treated as 0.
    • [NBT List / JSON Array][NBT Compound / JSON Object] merchant_predicate: Optional predicate on the merchant that needs to pass for this trade to be offered. The reference predicate is not supported.
    • [String][NBT List / JSON Array] double_trade_price_enchantments: Optional — Any number of enchantment(s) (an [String] ID, or a [String] tag with #, or an [NBT List / JSON Array] array containing [String] IDs). If present in the item [NBT Compound / JSON Object] gives's stored_enchantments component after the execution of [NBT List / JSON Array] given_item_modifiers, doubles the additional cost (defined by the additional_trade_cost component) of the item [NBT Compound / JSON Object] wants.

History

Java Edition
26.1snap1Villager trades are now data-driven.
Upcoming Java Edition
26.3snap4The given_item_modifiers field has been renamed to given_item_modifier.

Sources