Skip to main content
Version: 1.20.x

Data Trader

Loading data...

Defining the trades

File structure

The trader can receive an ID for a merchant offers "recipe". This is a list of single merchant offers. An example file could look like this:

data/modid/merchant_offers/example.json
{
"Recipes": [
{
"buy": {
"item": "minecraft:diamond",
"count": 3
},
"buyB": {
"item": "minecraft:wooden_pickaxe"
},
"sell": {
"item": "minecraft:diamond_pickaxe",
"nbt": "{Damage:0,Enchantments:[{id:\"minecraft:efficiency\",lvl:2},{id:\"minecraft:unbreaking\", lvl:10}]}"
},
"uses": 10,
"maxUses": 50,
"rewardExp": false,
"xp": 0,
"priceMultiplier": 0.0,
"specialPrice": 0,
"demand": 0
}
]
}
NameDefault valueDescription
buyThe item(s) player trades to receive sell.
buyBAirThe optional second item in a trade offer.
sellThe item(s) the trader provides in return.
uses0The current usage count of the trade.
maxUses4Maximum times the trade can be used before restocking is required.
rewardExpfalseWhether the player earns 3–6 XP per trade.
xp0XP amount the trader earns (not used).
priceMultiplier0.0Price modifier affecting the trade cost.
specialPrice0Additional price modifier (positive or negative).
demand0Dynamic demand modifier affecting price.

How to use?

You spawn the trader using the /summon command, or by using the spawn egg. After this, you use the command /datatrader setOffer @e <modid>:<path> to set the recipe. This can also be done by datapacks. For a normal trader, I recommend setting NoAI to true.