API reference / @jsprismarine/loot / LootRegistry
Class: LootRegistry
Defined in: loot/src/registry.ts:148
The loot tables a pack stack registered.
A table compiles on first use and stays compiled, so a chest opened a thousand times parses once. References between tables resolve through the same stack, and a reference that leads back to its own table reports a cycle instead of recursing.
Three of the content seams are answered from the stack rather than asked of the host, because the stack already carries what they need: LootContentOptions.recipes is the stack's own Java recipes, which is what furnace_smelt smelts through; LootContentOptions.itemTag expands an item tag a smelting ingredient names; and LootContentOptions.parse resolves the references a set_contents entry list may name. A host that passes any of them keeps its own.
Constructors
Constructor
new LootRegistry(
definitions,options?):LootRegistry
Defined in: loot/src/registry.ts:163
Parameters
definitions
options?
LootRegistryOptions = {}
Returns
LootRegistry
Properties
diagnostics
readonlydiagnostics:DiagnosticCollector
Defined in: loot/src/registry.ts:150
Everything parsing and rolling reported, in the order it was reported.
Accessors
cycles
Get Signature
get cycles(): readonly
LootTableCycle[]
Defined in: loot/src/registry.ts:291
Every cycle in the reference graph, found over the raw JSON without compiling anything. Computed once and kept.
Returns
readonly LootTableCycle[]
dialect
Get Signature
get dialect():
"java"|"bedrock"
Defined in: loot/src/registry.ts:184
Which edition's spelling the registered tables are written in, as the source stated it.
Returns
"java" | "bedrock"
findings
Get Signature
get findings(): readonly
LootFinding[]
Defined in: loot/src/registry.ts:211
Everything reported so far, each attributed to the table it came from.
This is diagnostics for a host that writes its own report, such as one naming the pack and the file a finding sits in. Call validate first for the whole picture; on its own this holds only what the tables compiled so far reported.
Returns
readonly LootFinding[]
ids
Get Signature
get ids(): readonly
string[]
Defined in: loot/src/registry.ts:179
The namespaced ids the pack stack registered, in load order.
Returns
readonly string[]
worldSeed
Get Signature
get worldSeed():
bigint
Defined in: loot/src/registry.ts:189
The world seed every sequenced stream is keyed from.
Returns
bigint
Methods
restoreRandomState()
restoreRandomState(
state):void
Defined in: loot/src/registry.ts:199
Restores the registry streams from a JSON-parsed state with the same world seed.
Parameters
state
unknown
Returns
void
roll()
roll(
id,request?): readonlyItemStack[]
Defined in: loot/src/registry.ts:261
Rolls a table by id. The context key set comes from the table and the randomness from the table's own sequence, so the only thing a caller has to supply is the loot context parameters.
Parameters
id
string
request?
LootRollRequest = {}
Returns
readonly ItemStack[]
saveRandomState()
saveRandomState():
LootSequencesState
Defined in: loot/src/registry.ts:194
Captures the advanced named and unkeyed streams used by this registry.
Returns
table()
table(
id):LootTable|undefined
Defined in: loot/src/registry.ts:233
Compiles a table, or returns undefined when the stack has no such id. Parse diagnostics land in diagnostics.
Parameters
id
string
Returns
LootTable | undefined
Throws
In strict mode, when the table reported an error.
validate()
validate(): readonly
Diagnostic[]
Defined in: loot/src/registry.ts:313
Compiles every registered table and walks the reference graph, so a malformed pack fails at load rather than at the first chest.
Runs once: a second call answers from what the first reported.
Returns
readonly Diagnostic[]
Everything reported so far, cycles included. findings is the same list with each entry's table named.
Throws
In strict mode, at the first table that reported an error.