Skip to content

API reference / @jsprismarine/trading

@jsprismarine/trading ​

Join the Discord Servernpm

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.

typescript
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 for

The 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".

  1. Count the unlocked tiers. The first always counts, and the scan stops at the first requirement the trader has not met.
  2. For each group of each unlocked tier, draw num_to_select trades without replacement, in proportion to their weight. A negative count offers the whole group, which is how 24 of the 130 vanilla groups and every normalized legacy tier are written.
  3. For each slot, keep the choices whose filters pass, draw one uniformly, and draw its quantity.
  4. 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 ​

FunctionWhat it does here
exploration_mapWrites minecraft:exploration_map with the destination. Locating the structure belongs to worldgen.
set_potionWrites minecraft:potion.
random_dyeWrites minecraft:dye_color, drawn from the 16 vanilla dyes.
random_aux_valueWrites minecraft:aux_value, drawn inside values.
random_block_stateWrites one entry of minecraft:block_states. 1.26.51.1 moved the coral trades onto it.
enchant_with_levelsDraws the level inside levels, then asks the TradeEnchanting seam to enchant.
enchant_book_for_tradingAsks 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. resupply runs Java's demand = 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 is base + floor(base * demand * price_multiplier).
  • The discount fields are flat deltas, not percentages. cured_discount of -25 to -20 off an emerald price is what a cured villager actually charges, and max_nearby_cured_discount of -200 only reads as a cap on a running total. Each nearby_cured villager adds nearby_cured_discount, Hero of the Village adds hero_demand_discount per 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. playerRewardExp replaces it.

The injected seams ​

  • TradeContext is the player and trader state. filters is the filter context a TradeItem's filters reads, which vanilla uses for in_overworld and is_mark_variant on the cartographer's maps and the fisherman's fish. heroOfTheVillage, curedByPlayer and nearbyCured are the whole of what the discounts need.
  • TradeEnchanting answers the two enchanting functions. Everything else a function needs is in its own body.
  • RandomSource from @jsprismarine/predicates is the only source of randomness.
  • OfferGenerationOptions.functions replaces the seven built-in functions outright.
  • report receives 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:

MeasureResult
Trade tables27: 14 economy and 13 legacy
Files that parse with no diagnostic27
Tiers110
Groups155, which is the 130 the files write plus one per legacy tier that holds its trades directly
Trades384
Trade item functions used6, all implemented
Offers generated for a fully experienced trader across all 27 tables225

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:

sh
JSP_VANILLA_TRADE_TABLES=1 pnpm --filter @jsprismarine/trading exec vitest run src/vanillaTradeTables.test.ts

What a later agent adds ​

  • The enchanting seam. TradeEnchanting has no implementation here. @jsprismarine/enchantments owns 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. resupply is a method, and deciding when the villager's minecraft:scheduler fires minecraft:resupply_trades belongs to the entity runtime.
  • The gossip system. nearbyCured is 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 ​

readonly max: number

Defined in: component.ts:15

min ​

readonly min: number

Defined in: component.ts:14


EconomyTradeTableSettings ​

Defined in: component.ts:19

What minecraft:economy_trade_table declares.

Properties ​

convertTradesEconomy ​

readonly convertTradesEconomy: boolean

Defined in: component.ts:27

Whether a legacy table's offers convert into economy offers on load.

curedDiscount ​

readonly curedDiscount: DiscountRange

Defined in: component.ts:30

The discount a villager the player cured applies, drawn inside the range.

displayName? ​

readonly optional displayName?: string

Defined in: component.ts:22

heroDemandDiscount ​

readonly heroDemandDiscount: number

Defined in: component.ts:38

The discount each level of Hero of the Village applies.

maxCuredDiscount ​

readonly maxCuredDiscount: DiscountRange

Defined in: component.ts:32

The furthest the cured discount may go.

maxNearbyCuredDiscount ​

readonly maxNearbyCuredDiscount: number

Defined in: component.ts:36

The furthest the nearby cured discounts may add up to.

nearbyCuredDiscount ​

readonly nearbyCuredDiscount: number

Defined in: component.ts:34

The discount each other cured villager nearby adds.

newScreen ​

readonly newScreen: boolean

Defined in: component.ts:23

persistTrades ​

readonly persistTrades: boolean

Defined in: component.ts:25

Whether the generated offers survive a save and reload.

showTradeScreen ​

readonly showTradeScreen: boolean

Defined in: component.ts:28

table? ​

readonly optional table?: string

Defined in: component.ts:21

The path of the table file, such as trading/economy_trades/farmer_trades.json.

useLegacyPriceFormula ​

readonly useLegacyPriceFormula: boolean

Defined in: component.ts:39


LiveOffer ​

Defined in: economy.ts:36

One offer as a trader shows it now.

Properties ​

available ​

readonly available: boolean

Defined in: economy.ts:41

Whether the trade still works before the next restock.

demand ​

readonly demand: number

Defined in: economy.ts:39

offer ​

readonly offer: TradeOffer

Defined in: economy.ts:37

uses ​

readonly uses: number

Defined in: economy.ts:38

wants ​

readonly wants: readonly TradeStack[]

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? ​

readonly optional context?: TradeContext

Defined in: economy.ts:100

enchanting? ​

readonly optional enchanting?: TradeEnchanting

Defined in: economy.ts:101

experience? ​

readonly optional experience?: number

Defined in: economy.ts:104

The trader's experience when it is loaded from a save rather than created.

functions? ​

readonly optional functions?: ReadonlyMap<string, TradeFunctionApplier>

Defined in: economy.ts:102

playerRewardExp? ​

readonly optional playerRewardExp?: 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 ​

readonly max: number

min ​

readonly min: number

random ​

readonly random: RandomSource

Defined in: economy.ts:97

report? ​

readonly optional report?: (code, message) => void

Defined in: economy.ts:110

Parameters ​
code ​

string

message ​

string

Returns ​

void

settings? ​

readonly optional settings?: EconomyTradeTableSettings

Defined in: economy.ts:99

The minecraft:economy_trade_table body, which carries the discount parameters.

snapshot? ​

readonly optional snapshot?: 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 ​

readonly table: 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? ​

readonly optional curedDiscount?: number

Defined in: economy.ts:90

experience ​

readonly experience: number

Defined in: economy.ts:88

generatedTiers ​

readonly generatedTiers: number

Defined in: economy.ts:89

offers ​

readonly offers: readonly OfferSnapshot[]

Defined in: economy.ts:91

version ​

readonly version: 1

Defined in: economy.ts:87


OfferGenerationOptions ​

Defined in: offers.ts:61

How to generate one trader's offers.

Properties ​

context? ​

readonly optional context?: TradeContext

Defined in: offers.ts:66

enchanting? ​

readonly optional enchanting?: TradeEnchanting

Defined in: offers.ts:67

functions? ​

readonly optional functions?: ReadonlyMap<string, TradeFunctionApplier>

Defined in: offers.ts:69

Replaces the six vanilla trade item functions.

random ​

readonly random: RandomSource

Defined in: offers.ts:63

report? ​

readonly optional report?: (code, message) => void

Defined in: offers.ts:70

Parameters ​
code ​

string

message ​

string

Returns ​

void

table ​

readonly table: TradeTable

Defined in: offers.ts:62

traderExp? ​

readonly optional traderExp?: 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 ​

readonly demand: number

Defined in: economy.ts:78

gives ​

readonly gives: readonly StackSnapshot[]

Defined in: economy.ts:72

maxUses ​

readonly maxUses: number

Defined in: economy.ts:75

priceMultipliers ​

readonly priceMultipliers: readonly number[]

Defined in: economy.ts:73

rewardExp ​

readonly rewardExp: boolean

Defined in: economy.ts:76

tier ​

readonly tier: number

Defined in: economy.ts:70

traderExp ​

readonly traderExp: number

Defined in: economy.ts:74

uses ​

readonly uses: number

Defined in: economy.ts:77

wants ​

readonly wants: readonly StackSnapshot[]

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 ​

readonly max: number

Defined in: tables.ts:28

min ​

readonly min: 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 ​

readonly components: readonly (readonly [string, unknown])[]

Defined in: economy.ts:65

count ​

readonly count: number

Defined in: economy.ts:64

item ​

readonly item: 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? ​

readonly optional curedByPlayer?: boolean

Defined in: offers.ts:55

Whether the trading player cured this trader of being a zombie villager.

filters? ​

readonly optional filters?: 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? ​

readonly optional heroOfTheVillage?: number

Defined in: offers.ts:53

The level of Hero of the Village the trading player carries, zero for none.

nearbyCured? ​

readonly optional nearbyCured?: 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 ​

readonly gives: readonly TradeItemSlot[]

Defined in: tables.ts:64

maxUses ​

readonly maxUses: number

Defined in: tables.ts:68

How many times the trade works before the trader restocks.

rewardExp ​

readonly rewardExp: boolean

Defined in: tables.ts:70

Whether the player earns experience from the trade.

traderExp ​

readonly traderExp: number

Defined in: tables.ts:66

The experience the trader earns per use, which is what unlocks the next tier.

wants ​

readonly wants: readonly TradeItemSlot[]

Defined in: tables.ts:63

weight ​

readonly weight: 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()? ​

optional enchantBookForTrading(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 ​

RandomSource

Returns ​

{ components: ReadonlyMap<string, unknown>; level: number; } | undefined

The enchantment's level, which drives the emerald cost, and the components to write.

enchantWithLevels()? ​

optional enchantWithLevels(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 ​

RandomSource

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? ​

readonly optional enchanting?: TradeEnchanting

Defined in: functions.ts:65

random ​

readonly random: RandomSource

Defined in: functions.ts:64

report? ​

readonly optional report?: (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? ​

readonly optional costOverride?: 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 ​

readonly stack: 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 ​

readonly body: Readonly<Record<string, unknown>>

Defined in: tables.ts:36

The function's body, including the function key itself.

name ​

readonly name: 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 ​

readonly numToSelect: number

Defined in: tables.ts:78

How many trades to offer. A negative number offers every trade in the group.

trades ​

readonly trades: readonly TradeDefinition[]

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? ​

readonly optional filters?: Filter

Defined in: tables.ts:47

The filters that decide whether this item may be offered at all.

functions ​

readonly functions: readonly TradeFunctionSpec[]

Defined in: tables.ts:45

item ​

readonly item: string

Defined in: tables.ts:41

priceMultiplier ​

readonly priceMultiplier: number

Defined in: tables.ts:44

How much demand raises this item's price, per point of demand.

quantity ​

readonly quantity: 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 ​

readonly choices: readonly TradeItem[]

Defined in: tables.ts:58


TradeOffer ​

Defined in: offers.ts:24

One generated offer, before demand and the discounts touch its price.

Properties ​

gives ​

readonly gives: readonly TradeStack[]

Defined in: offers.ts:29

maxUses ​

readonly maxUses: number

Defined in: offers.ts:34

priceMultipliers ​

readonly priceMultipliers: readonly number[]

Defined in: offers.ts:31

How much demand raises each want, aligned with wants.

rewardExp ​

readonly rewardExp: boolean

Defined in: offers.ts:35

tier ​

readonly tier: number

Defined in: offers.ts:26

The tier the offer came from, counting from zero.

traderExp ​

readonly traderExp: number

Defined in: offers.ts:33

The experience the trader earns per use.

wants ​

readonly wants: readonly TradeStack[]

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? ​

readonly optional gives?: readonly TradeStack[]

Defined in: economy.ts:52

leveledUp ​

readonly leveledUp: boolean

Defined in: economy.ts:58

Whether the trade unlocked a tier and added its offers.

playerExperience ​

readonly playerExperience: number

Defined in: economy.ts:56

The experience the player earned, zero when the trade's reward_exp is false.

refusal? ​

readonly optional refusal?: TradeRefusal

Defined in: economy.ts:49

traded ​

readonly traded: boolean

Defined in: economy.ts:48

traderExperience ​

readonly traderExperience: number

Defined in: economy.ts:54

The experience the trader earned.

wants? ​

readonly optional wants?: readonly TradeStack[]

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 ​

readonly components: ReadonlyMap<string, unknown>

Defined in: functions.ts:22

What the item's functions wrote, keyed by the component each one sets.

count ​

readonly count: number

Defined in: functions.ts:20

item ​

readonly item: string

Defined in: functions.ts:19


TradeTable ​

Defined in: tables.ts:89

One parsed trading/*.json.

Properties ​

formatVersion? ​

readonly optional formatVersion?: string

Defined in: tables.ts:90

tiers ​

readonly tiers: readonly TradeTier[]

Defined in: tables.ts:91


TradeTableParseOptions ​

Defined in: tables.ts:95

Where a parse reports its findings.

Properties ​

pack ​

readonly pack: string

Defined in: tables.ts:96

path? ​

readonly optional path?: string

Defined in: tables.ts:97

report? ​

readonly optional report?: (diagnostic) => void

Defined in: tables.ts:98

Parameters ​
diagnostic ​

Diagnostic

Returns ​

void


TradeTableSettings ​

Defined in: component.ts:43

What minecraft:trade_table declares, which is the legacy component's smaller body.

Properties ​

convertTradesEconomy ​

readonly convertTradesEconomy: boolean

Defined in: component.ts:46

displayName? ​

readonly optional displayName?: string

Defined in: component.ts:45

table? ​

readonly optional table?: string

Defined in: component.ts:44


TradeTier ​

Defined in: tables.ts:83

One tier, unlocked once the trader's experience reaches totalExpRequired.

Properties ​

groups ​

readonly groups: readonly TradeGroup[]

Defined in: tables.ts:85

totalExpRequired ​

readonly totalExpRequired: 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 ​

TradeStack

spec ​

TradeFunctionSpec

context ​

TradeFunctionContext

Returns ​

TradeFunctionOutcome


TradeRefusal ​

TradeRefusal = "noSuchOffer" | "outOfStock"

Defined in: economy.ts:33

Why a trade did not happen.

Variables ​

DYE_COLOR_COUNT ​

const DYE_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 ​

const VANILLA_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 ​

TradeStack

specs ​

readonly TradeFunctionSpec[]

context ​

TradeFunctionContext

registry? ​

ReadonlyMap<string, TradeFunctionApplier> = VANILLA_TRADE_FUNCTIONS

Returns ​

TradeFunctionOutcome

The stack with each function's components, and the last cost any of them set.


generateOffers() ​

generateOffers(options): readonly TradeOffer[]

Defined in: offers.ts:186

Generates the offers of one trader.

Parameters ​

options ​

OfferGenerationOptions

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 ​

EconomyTradeTableSettings


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 ​

TradeTableParseOptions

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 ​

TradeTableSettings


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 ​

TradeTable

traderExp ​

number

Returns ​

number