API reference / @jsprismarine/trading / Merchant
Class: Merchant
Defined in: economy.ts:227
One trader's offers and their economy.
A caller creates one per villager or wandering trader, asks it for offers, and calls trade and resupply. The offers are generated once, which is what persist_trades means, and a level up appends the new tier's offers rather than redrawing the old ones.
Constructors
Constructor
new Merchant(
options):Merchant
Defined in: economy.ts:238
Parameters
options
Returns
Merchant
Accessors
experience
Get Signature
get experience():
number
Defined in: economy.ts:303
The trader's experience, which is what unlocks tiers.
Returns
number
level
Get Signature
get level():
number
Defined in: economy.ts:313
The trader's level, which is how many tiers its experience has unlocked.
Returns
number
Methods
offers()
offers(
context?): readonlyLiveOffer[]
Defined in: economy.ts:323
The offers as a player sees them now.
Parameters
context?
The player's state, which the discounts read. Falls back to the context the merchant was built with.
Returns
readonly LiveOffer[]
resupply()
resupply():
void
Defined in: economy.ts:376
Restocks every offer, which is what minecraft:trade_resupply asks for.
Demand moves first, by Java's rule: a trade used to its limit gains its whole use count, and a trade nobody touched loses it.
Returns
void
snapshot()
snapshot():
MerchantSnapshot
Defined in: economy.ts:282
The state a save has to keep for this trader to come back as the same trader.
Returns
tierRequirements()
tierRequirements(): readonly
number[]
Defined in: economy.ts:308
The experience each tier needs, in tier order, which the trade screen draws as its progress bar.
Returns
readonly number[]
trade()
trade(
index,context?):TradeResult
Defined in: economy.ts:339
Runs one trade.
Parameters
index
number
The offer's position in offers.
context?
Returns
What the player paid and earned, or the refusal.