API reference / @jsprismarine/trading
@jsprismarine/trading
Bedrock trade tables: the economy and legacy grammars, offer generation, and the villager economy of uses, demand, experience, levels, restock and discounts. It builds on @jsprismarine/packs for the filter grammar, on @jsprismarine/entities for the filter evaluator that spawn rules, entity definitions and trade tables all share, and on @jsprismarine/predicates for the injected random source.
import { Merchant, parseEconomyTradeTable, parseTradeTable } from '@jsprismarine/trading';
import { seededRandom } from '@jsprismarine/predicates';
const table = parseTradeTable(file.data, { pack: file.pack, path: file.path })!;
const settings = parseEconomyTradeTable(villager.componentParams('minecraft:economy_trade_table'));
const merchant = new Merchant({ table, settings, random: seededRandom(villagerSeed), enchanting });
merchant.offers({ heroOfTheVillage: 2 }); // what this player pays today
merchant.trade(0, { heroOfTheVillage: 2 });
merchant.resupply(); // what `minecraft:trade_resupply` asks forThe two grammars
A file is {"tiers": [...]}, optionally with a format_version; 17 of the 27 vanilla files write no version. Trade Table.json requires groups under a tier, and the documentation shows trades directly under one, which is what 7 of the 13 legacy trading/*.json tables write. Both forms parse, and a bare trades list becomes one group that selects all of its trades, so everything downstream sees one shape.
tiers[] { total_exp_required, groups[] { num_to_select, trades[] {
wants[], gives[], trader_exp, max_uses, reward_exp, weight } } }A member of wants or gives is a TradeItem or {choice: [TradeItem]}, and a TradeItem is {item, quantity, price_multiplier, functions[], filters}. Both forms become a TradeItemSlot holding a list of choices, so a plain item is a choice of one. A quantity reads as a number, as {min, max} or as {max} alone, which is the third shape vanilla writes.
minecraft:economy_trade_table and the legacy minecraft:trade_table parse here too, because the discount fields the economy needs live on the component rather than in the table. Every vanilla villager writes the ranges as two-member arrays rather than as {min, max}, and both read.
Where the schema and the documentation disagree
The schema gives max_uses 7, price_multiplier 0 and num_to_select 0; the documentation pages give 12, 0.05 and 1. This package takes the documentation's, because the documentation describes the running engine and the schema describes an editor. Vanilla sets max_uses and price_multiplier explicitly on almost every economy trade, so the choice only reaches custom packs and the legacy tables.
Offer generation
generateOffers follows the three rules the documentation states: "Tiers are unlocked by the trading experience of the villager, not the player. The first tier in a list of trade tiers is always available"; "once the trading system hits a tier that requires more experience points than the trader has, subsequent tiers won't be checked"; and num_to_select is "the number of trades from the trades array to make available".
- Count the unlocked tiers. The first always counts, and the scan stops at the first requirement the trader has not met.
- For each group of each unlocked tier, draw
num_to_selecttrades without replacement, in proportion to theirweight. A negative count offers the whole group, which is how 24 of the 130 vanilla groups and every normalized legacy tier are written. - For each slot, keep the choices whose
filterspass, draw one uniformly, and draw its quantity. - Run the item's functions.
Every draw goes through the injected RandomSource, so one seed gives one trader the same offers every time.
The trade item functions
| Function | What it does here |
|---|---|
exploration_map | Writes minecraft:exploration_map with the destination. Locating the structure belongs to worldgen. |
set_potion | Writes minecraft:potion. |
random_dye | Writes minecraft:dye_color, drawn from the 16 vanilla dyes. |
random_aux_value | Writes minecraft:aux_value, drawn inside values. |
random_block_state | Writes one entry of minecraft:block_states. 1.26.51.1 moved the coral trades onto it. |
enchant_with_levels | Draws the level inside levels, then asks the TradeEnchanting seam to enchant. |
enchant_book_for_trading | Asks the seam for the enchantment and its level, then prices the trade. |
enchant_book_for_trading is the one vanilla function that sets a price. The librarian's book trade writes an emerald want with no quantity, so the cost has to come from the function's four parameters: base_cost + random(0, base_random_cost + level * per_level_random_cost) + level * per_level_cost. That arithmetic lives here and the enchantment choice goes to the seam, so the price is testable without the enchantment tables. The cost lands on the trade's first want, which is the emerald side of every vanilla trade.
A function with no seam reports trading.noEnchanter and the trade still appears, so one missing dependency does not empty a villager.
The economy
Mojang names the fields and publishes none of the formulas. The documentation says price_multiplier "sets how much the item's price can increase due to supply and demand changes", max_uses is "how many times the trade can be made before the trader needs to restock", minecraft:trade_resupply "Resupplies an entity's trade", and that cured_discount, nearby_cured_discount and hero_demand_discount exist. The formulas, the restock schedule, the gossip system and the mapping from trader_exp to a villager level are written down nowhere.
So Merchant uses Java Edition's model, which is the only published one, and names the three places where it had to choose.
- Levels come from the table. A trader's level is how many tiers its experience has unlocked, so no separate experience-to-level mapping is needed. A level up appends the new tier's offers and leaves the earlier ones, with their uses, alone.
- Demand moves at restock, not inside a stock cycle.
resupplyruns Java'sdemand = demand + uses - (maxUses - uses), clamped at zero, and then clears the uses. A trade sold out twelve times comes back at demand 12; a trade nobody touched falls back toward zero. The price isbase + floor(base * demand * price_multiplier). - The discount fields are flat deltas, not percentages.
cured_discountof -25 to -20 off an emerald price is what a cured villager actually charges, andmax_nearby_cured_discountof -200 only reads as a cap on a running total. Eachnearby_curedvillager addsnearby_cured_discount, Hero of the Village addshero_demand_discountper level, the cured discount is drawn once so the price does not flicker, the discounts land on the first want alone, and no price falls below one item. - The player's reward is Java's 3 to 6. Bedrock publishes no number.
playerRewardExpreplaces it.
The injected seams
TradeContextis the player and trader state.filtersis the filter context aTradeItem'sfiltersreads, which vanilla uses forin_overworldandis_mark_varianton the cartographer's maps and the fisherman's fish.heroOfTheVillage,curedByPlayerandnearbyCuredare the whole of what the discounts need.TradeEnchantinganswers the two enchanting functions. Everything else a function needs is in its own body.RandomSourcefrom@jsprismarine/predicatesis the only source of randomness.OfferGenerationOptions.functionsreplaces the seven built-in functions outright.reportreceives every unknown function, missing seam, unanswered filter test and dropped trade.
Measured coverage
Against bedrock-samples v1.26.50.4, which ships all 27 trade tables as text, through the corpus test in src/vanillaTradeTables.test.ts:
| Measure | Result |
|---|---|
| Trade tables | 27: 14 economy and 13 legacy |
| Files that parse with no diagnostic | 27 |
| Tiers | 110 |
| Groups | 155, which is the 130 the files write plus one per legacy tier that holds its trades directly |
| Trades | 384 |
| Trade item functions used | 6, all implemented |
| Offers generated for a fully experienced trader across all 27 tables | 225 |
The test also runs the composed Bedrock Dedicated Server 1.26.51.1 tables when they are cached. BDS ships 11 of the 27 as the undocumented \x7fMCB binary, which the test resolves through the bedrock-samples copy of the same name, and its tables differ from 1.26.50.4 in content: the wandering trader drops from 100 trades to 25, and the coral trades move from random_aux_value to random_block_state. That pass checks that every file parses and every function is implemented rather than pinning numbers that move with a patch release.
Both passes need the sources that pnpm --filter @jsprismarine/bedrock-data run fetch:sources caches and run only with JSP_VANILLA_TRADE_TABLES set:
JSP_VANILLA_TRADE_TABLES=1 pnpm --filter @jsprismarine/trading exec vitest run src/vanillaTradeTables.test.tsWhat a later agent adds
- The enchanting seam.
TradeEnchantinghas no implementation here.@jsprismarine/enchantmentsowns the tables that answer it. convert_trades_economy. The legacy component asks the engine to regenerate a trader's offers against an economy table while keeping the same trades where it can. The field parses; the conversion does not run.- The restock schedule.
resupplyis a method, and deciding when the villager'sminecraft:schedulerfiresminecraft:resupply_tradesbelongs to the entity runtime. - The gossip system.
nearbyCuredis a number the host supplies. Nothing here tracks which villagers gossip about which player.
Saving a trader
merchant.snapshot() returns plain JSON: the offers a trader generated, the uses and demand on each, its experience and the cured discount it drew. Pass it back as new Merchant({ ..., snapshot }) and the trader comes back as the same trader, with nothing drawn again, whatever random source it is given. A tier the save lacks, because the table gained one since, is generated on top. merchantSnapshotIn(value) checks a parsed snapshot field by field and returns undefined for anything damaged, so a corrupt save draws fresh offers rather than trading from numbers nothing vouches for.
Classes
Interfaces
DiscountRange
Defined in: component.ts:13
A {min, max} body, which vanilla writes as a two-member array.
Properties
max
readonlymax:number
Defined in: component.ts:15
min
readonlymin:number
Defined in: component.ts:14
EconomyTradeTableSettings
Defined in: component.ts:19
What minecraft:economy_trade_table declares.
Properties
convertTradesEconomy
readonlyconvertTradesEconomy:boolean
Defined in: component.ts:27
Whether a legacy table's offers convert into economy offers on load.
curedDiscount
readonlycuredDiscount:DiscountRange
Defined in: component.ts:30
The discount a villager the player cured applies, drawn inside the range.
displayName?
readonlyoptionaldisplayName?:string
Defined in: component.ts:22
heroDemandDiscount
readonlyheroDemandDiscount:number
Defined in: component.ts:38
The discount each level of Hero of the Village applies.
maxCuredDiscount
readonlymaxCuredDiscount:DiscountRange
Defined in: component.ts:32
The furthest the cured discount may go.
maxNearbyCuredDiscount
readonlymaxNearbyCuredDiscount:number
Defined in: component.ts:36
The furthest the nearby cured discounts may add up to.
nearbyCuredDiscount
readonlynearbyCuredDiscount:number
Defined in: component.ts:34
The discount each other cured villager nearby adds.
newScreen
readonlynewScreen:boolean
Defined in: component.ts:23
persistTrades
readonlypersistTrades:boolean
Defined in: component.ts:25
Whether the generated offers survive a save and reload.
showTradeScreen
readonlyshowTradeScreen:boolean
Defined in: component.ts:28
table?
readonlyoptionaltable?:string
Defined in: component.ts:21
The path of the table file, such as trading/economy_trades/farmer_trades.json.
useLegacyPriceFormula
readonlyuseLegacyPriceFormula:boolean
Defined in: component.ts:39
LiveOffer
Defined in: economy.ts:36
One offer as a trader shows it now.
Properties
available
readonlyavailable:boolean
Defined in: economy.ts:41
Whether the trade still works before the next restock.
demand
readonlydemand:number
Defined in: economy.ts:39
offer
readonlyoffer:TradeOffer
Defined in: economy.ts:37
uses
readonlyuses:number
Defined in: economy.ts:38
wants
readonlywants: readonlyTradeStack[]
Defined in: economy.ts:43
What the player pays now, after demand and the discounts.
MerchantOptions
Defined in: economy.ts:95
How to build a Merchant.
Properties
context?
readonlyoptionalcontext?:TradeContext
Defined in: economy.ts:100
enchanting?
readonlyoptionalenchanting?:TradeEnchanting
Defined in: economy.ts:101
experience?
readonlyoptionalexperience?:number
Defined in: economy.ts:104
The trader's experience when it is loaded from a save rather than created.
functions?
readonlyoptionalfunctions?:ReadonlyMap<string,TradeFunctionApplier>
Defined in: economy.ts:102
playerRewardExp?
readonlyoptionalplayerRewardExp?:object
Defined in: economy.ts:109
How much experience a trade with reward_exp gives the player. Mojang publishes no number; the default is Java's 3 to 6 for a villager.
max
readonlymax:number
min
readonlymin:number
random
readonlyrandom:RandomSource
Defined in: economy.ts:97
report?
readonlyoptionalreport?: (code,message) =>void
Defined in: economy.ts:110
Parameters
code
string
message
string
Returns
void
settings?
readonlyoptionalsettings?:EconomyTradeTableSettings
Defined in: economy.ts:99
The minecraft:economy_trade_table body, which carries the discount parameters.
snapshot?
readonlyoptionalsnapshot?:MerchantSnapshot
Defined in: economy.ts:116
What Merchant.snapshot saved. The offers, uses, demand, experience and cured discount come back exactly, and nothing is drawn again for tiers the snapshot already holds, which is what persist_trades asks for across a restart. Takes precedence over experience.
table
readonlytable:TradeTable
Defined in: economy.ts:96
MerchantSnapshot
Defined in: economy.ts:86
Everything about a trader that cannot be drawn again: the offers it generated, how much of each was used, the demand on each, its experience and the cured discount it drew. Plain JSON, so a save can hold it as a string.
Properties
curedDiscount?
readonlyoptionalcuredDiscount?:number
Defined in: economy.ts:90
experience
readonlyexperience:number
Defined in: economy.ts:88
generatedTiers
readonlygeneratedTiers:number
Defined in: economy.ts:89
offers
readonlyoffers: readonlyOfferSnapshot[]
Defined in: economy.ts:91
version
readonlyversion:1
Defined in: economy.ts:87
OfferGenerationOptions
Defined in: offers.ts:61
How to generate one trader's offers.
Properties
context?
readonlyoptionalcontext?:TradeContext
Defined in: offers.ts:66
enchanting?
readonlyoptionalenchanting?:TradeEnchanting
Defined in: offers.ts:67
functions?
readonlyoptionalfunctions?:ReadonlyMap<string,TradeFunctionApplier>
Defined in: offers.ts:69
Replaces the six vanilla trade item functions.
random
readonlyrandom:RandomSource
Defined in: offers.ts:63
report?
readonlyoptionalreport?: (code,message) =>void
Defined in: offers.ts:70
Parameters
code
string
message
string
Returns
void
table
readonlytable:TradeTable
Defined in: offers.ts:62
traderExp?
readonlyoptionaltraderExp?:number
Defined in: offers.ts:65
The trader's experience, which decides how many tiers unlock. Zero for a new trader.
OfferSnapshot
Defined in: economy.ts:69
One offer as a save holds it: what it is, and how far its stock and price have moved.
Properties
demand
readonlydemand:number
Defined in: economy.ts:78
gives
readonlygives: readonlyStackSnapshot[]
Defined in: economy.ts:72
maxUses
readonlymaxUses:number
Defined in: economy.ts:75
priceMultipliers
readonlypriceMultipliers: readonlynumber[]
Defined in: economy.ts:73
rewardExp
readonlyrewardExp:boolean
Defined in: economy.ts:76
tier
readonlytier:number
Defined in: economy.ts:70
traderExp
readonlytraderExp:number
Defined in: economy.ts:74
uses
readonlyuses:number
Defined in: economy.ts:77
wants
readonlywants: readonlyStackSnapshot[]
Defined in: economy.ts:71
QuantityRange
Defined in: tables.ts:26
An inclusive quantity range. A trade item that writes one number has min equal to max.
Properties
max
readonlymax:number
Defined in: tables.ts:28
min
readonlymin:number
Defined in: tables.ts:27
StackSnapshot
Defined in: economy.ts:62
One item stack of a saved offer, with its components as entries so it survives JSON.
Properties
components
readonlycomponents: readonly (readonly [string,unknown])[]
Defined in: economy.ts:65
count
readonlycount:number
Defined in: economy.ts:64
item
readonlyitem:string
Defined in: economy.ts:63
TradeContext
Defined in: offers.ts:44
What a trader and the player facing it look like to a trade table.
Offer generation reads filters; the economy reads the other three, which are the whole of the player state the discounts need.
Properties
curedByPlayer?
readonlyoptionalcuredByPlayer?:boolean
Defined in: offers.ts:55
Whether the trading player cured this trader of being a zombie villager.
filters?
readonlyoptionalfilters?:FilterContext
Defined in: offers.ts:51
The filter context TradeItem.filters reads. Vanilla's two uses are in_overworld and is_mark_variant on self, which select the cartographer's maps and the fisherman's fish by the trader's biome variant.
heroOfTheVillage?
readonlyoptionalheroOfTheVillage?:number
Defined in: offers.ts:53
The level of Hero of the Village the trading player carries, zero for none.
nearbyCured?
readonlyoptionalnearbyCured?:number
Defined in: offers.ts:57
How many other cured villagers stand near this trader.
TradeDefinition
Defined in: tables.ts:62
One trade: what it takes, what it gives and what it costs the trader.
Properties
gives
readonlygives: readonlyTradeItemSlot[]
Defined in: tables.ts:64
maxUses
readonlymaxUses:number
Defined in: tables.ts:68
How many times the trade works before the trader restocks.
rewardExp
readonlyrewardExp:boolean
Defined in: tables.ts:70
Whether the player earns experience from the trade.
traderExp
readonlytraderExp:number
Defined in: tables.ts:66
The experience the trader earns per use, which is what unlocks the next tier.
wants
readonlywants: readonlyTradeItemSlot[]
Defined in: tables.ts:63
weight
readonlyweight:number
Defined in: tables.ts:72
The weight of this trade in its group's draw.
TradeEnchanting
Defined in: functions.ts:26
The enchantment seam the two enchanting functions reach.
Methods
enchantBookForTrading()?
optionalenchantBookForTrading(item,random): {components:ReadonlyMap<string,unknown>;level:number; } |undefined
Defined in: functions.ts:45
Picks the single enchantment a traded book carries.
Parameters
item
string
random
Returns
{ components: ReadonlyMap<string, unknown>; level: number; } | undefined
The enchantment's level, which drives the emerald cost, and the components to write.
enchantWithLevels()?
optionalenchantWithLevels(item,levels,treasure,random):ReadonlyMap<string,unknown> |undefined
Defined in: functions.ts:33
Enchants a stack as enchant_with_levels asks.
Parameters
item
string
levels
number
The enchanting level already drawn from the function's range.
treasure
boolean
random
Returns
ReadonlyMap<string, unknown> | undefined
The components to write, or undefined when the item takes no enchantment.
TradeFunctionContext
Defined in: functions.ts:63
Everything a function needs beyond the stack and its own body.
Properties
enchanting?
readonlyoptionalenchanting?:TradeEnchanting
Defined in: functions.ts:65
random
readonlyrandom:RandomSource
Defined in: functions.ts:64
report?
readonlyoptionalreport?: (code,message) =>void
Defined in: functions.ts:67
Receives a function the registry does not hold and a seam the caller did not supply.
Parameters
code
string
message
string
Returns
void
TradeFunctionOutcome
Defined in: functions.ts:52
What one function did to a stack.
Properties
costOverride?
readonlyoptionalcostOverride?:number
Defined in: functions.ts:59
An emerald cost the function sets on the trade. enchant_book_for_trading is the one vanilla function that does, because the price of an enchanted book follows the enchantment it drew.
stack
readonlystack:TradeStack
Defined in: functions.ts:53
TradeFunctionSpec
Defined in: tables.ts:32
One loot function on a trade item, kept whole so the applier reads its own fields.
Properties
body
readonlybody:Readonly<Record<string,unknown>>
Defined in: tables.ts:36
The function's body, including the function key itself.
name
readonlyname:string
Defined in: tables.ts:34
The function field, such as enchant_with_levels.
TradeGroup
Defined in: tables.ts:76
One num_to_select draw over a list of trades.
Properties
numToSelect
readonlynumToSelect:number
Defined in: tables.ts:78
How many trades to offer. A negative number offers every trade in the group.
trades
readonlytrades: readonlyTradeDefinition[]
Defined in: tables.ts:79
TradeItem
Defined in: tables.ts:40
One TradeItem: what the trade wants or gives before its quantity is drawn.
Properties
filters?
readonlyoptionalfilters?:Filter
Defined in: tables.ts:47
The filters that decide whether this item may be offered at all.
functions
readonlyfunctions: readonlyTradeFunctionSpec[]
Defined in: tables.ts:45
item
readonlyitem:string
Defined in: tables.ts:41
priceMultiplier
readonlypriceMultiplier:number
Defined in: tables.ts:44
How much demand raises this item's price, per point of demand.
quantity
readonlyquantity:QuantityRange
Defined in: tables.ts:42
TradeItemSlot
Defined in: tables.ts:57
One member of wants or gives.
The grammar writes either a TradeItem or {choice: [TradeItem]}. Both become a list, so a plain item is a choice of one and offer generation has one case to handle.
Properties
choices
readonlychoices: readonlyTradeItem[]
Defined in: tables.ts:58
TradeOffer
Defined in: offers.ts:24
One generated offer, before demand and the discounts touch its price.
Properties
gives
readonlygives: readonlyTradeStack[]
Defined in: offers.ts:29
maxUses
readonlymaxUses:number
Defined in: offers.ts:34
priceMultipliers
readonlypriceMultipliers: readonlynumber[]
Defined in: offers.ts:31
How much demand raises each want, aligned with wants.
rewardExp
readonlyrewardExp:boolean
Defined in: offers.ts:35
tier
readonlytier:number
Defined in: offers.ts:26
The tier the offer came from, counting from zero.
traderExp
readonlytraderExp:number
Defined in: offers.ts:33
The experience the trader earns per use.
wants
readonlywants: readonlyTradeStack[]
Defined in: offers.ts:28
What the offer costs, at the quantity the table drew.
TradeResult
Defined in: economy.ts:47
What one attempt to trade produced.
Properties
gives?
readonlyoptionalgives?: readonlyTradeStack[]
Defined in: economy.ts:52
leveledUp
readonlyleveledUp:boolean
Defined in: economy.ts:58
Whether the trade unlocked a tier and added its offers.
playerExperience
readonlyplayerExperience:number
Defined in: economy.ts:56
The experience the player earned, zero when the trade's reward_exp is false.
refusal?
readonlyoptionalrefusal?:TradeRefusal
Defined in: economy.ts:49
traded
readonlytraded:boolean
Defined in: economy.ts:48
traderExperience
readonlytraderExperience:number
Defined in: economy.ts:54
The experience the trader earned.
wants?
readonlyoptionalwants?: readonlyTradeStack[]
Defined in: economy.ts:51
What the player paid, at the price the discounts and demand set.
TradeStack
Defined in: functions.ts:18
One resolved item of an offer.
Properties
components
readonlycomponents:ReadonlyMap<string,unknown>
Defined in: functions.ts:22
What the item's functions wrote, keyed by the component each one sets.
count
readonlycount:number
Defined in: functions.ts:20
item
readonlyitem:string
Defined in: functions.ts:19
TradeTable
Defined in: tables.ts:89
One parsed trading/*.json.
Properties
formatVersion?
readonlyoptionalformatVersion?:string
Defined in: tables.ts:90
tiers
readonlytiers: readonlyTradeTier[]
Defined in: tables.ts:91
TradeTableParseOptions
Defined in: tables.ts:95
Where a parse reports its findings.
Properties
pack
readonlypack:string
Defined in: tables.ts:96
path?
readonlyoptionalpath?:string
Defined in: tables.ts:97
report?
readonlyoptionalreport?: (diagnostic) =>void
Defined in: tables.ts:98
Parameters
diagnostic
Returns
void
TradeTableSettings
Defined in: component.ts:43
What minecraft:trade_table declares, which is the legacy component's smaller body.
Properties
convertTradesEconomy
readonlyconvertTradesEconomy:boolean
Defined in: component.ts:46
displayName?
readonlyoptionaldisplayName?:string
Defined in: component.ts:45
table?
readonlyoptionaltable?:string
Defined in: component.ts:44
TradeTier
Defined in: tables.ts:83
One tier, unlocked once the trader's experience reaches totalExpRequired.
Properties
groups
readonlygroups: readonlyTradeGroup[]
Defined in: tables.ts:85
totalExpRequired
readonlytotalExpRequired:number
Defined in: tables.ts:84
Type Aliases
TradeFunctionApplier
TradeFunctionApplier = (
stack,spec,context) =>TradeFunctionOutcome
Defined in: functions.ts:71
Applies one function to a stack.
Parameters
stack
spec
context
Returns
TradeRefusal
TradeRefusal =
"noSuchOffer"|"outOfStock"
Defined in: economy.ts:33
Why a trade did not happen.
Variables
DYE_COLOR_COUNT
constDYE_COLOR_COUNT:16=16
Defined in: functions.ts:114
The 16 dye indices random_dye draws from, which is the vanilla dye palette's size.
VANILLA_TRADE_FUNCTIONS
constVANILLA_TRADE_FUNCTIONS:ReadonlyMap<string,TradeFunctionApplier>
Defined in: functions.ts:190
The seven functions vanilla's trade tables use.
Functions
applyTradeFunctions()
applyTradeFunctions(
stack,specs,context,registry?):TradeFunctionOutcome
Defined in: functions.ts:206
Runs every function of one item in order.
Parameters
stack
specs
readonly TradeFunctionSpec[]
context
registry?
ReadonlyMap<string, TradeFunctionApplier> = VANILLA_TRADE_FUNCTIONS
Returns
The stack with each function's components, and the last cost any of them set.
generateOffers()
generateOffers(
options): readonlyTradeOffer[]
Defined in: offers.ts:186
Generates the offers of one trader.
Parameters
options
Returns
readonly TradeOffer[]
One offer per selected trade of every unlocked tier, in tier and group order. A trade whose wants or gives has a slot no choice survives is dropped and reported.
merchantSnapshotIn()
merchantSnapshotIn(
value):MerchantSnapshot|undefined
Defined in: economy.ts:163
Reads a saved snapshot back, checking every field it will use.
Parameters
value
unknown
Parsed JSON, from a save that may be old, hand-edited or damaged.
Returns
MerchantSnapshot | undefined
The snapshot, or undefined when anything about it is wrong; the caller then lets the trader draw its offers afresh rather than trading from numbers nothing vouches for.
parseEconomyTradeTable()
parseEconomyTradeTable(
value):EconomyTradeTableSettings
Defined in: component.ts:78
Reads minecraft:economy_trade_table, filling in the documented defaults.
Parameters
value
unknown
Returns
parseTradeTable()
parseTradeTable(
file,options):TradeTable|undefined
Defined in: tables.ts:250
Parses one trading/*.json file, in either the economy or the legacy form.
Parameters
file
unknown
options
Returns
TradeTable | undefined
The table, or undefined when the file has no tiers array. A malformed tier, group, trade or item is dropped and reported; everything else loads.
parseTradeTableComponent()
parseTradeTableComponent(
value):TradeTableSettings
Defined in: component.ts:101
Reads the legacy minecraft:trade_table.
Parameters
value
unknown
Returns
unlockedTierCount()
unlockedTierCount(
table,traderExp):number
Defined in: offers.ts:79
How many tiers a trader with this much experience has unlocked.
The first tier is always available, and the scan stops at the first tier whose requirement the trader has not met.
Parameters
table
traderExp
number
Returns
number