Skip to content

API reference / @jsprismarine/predicates / PredicateContext

Class: PredicateContext ​

Defined in: context.ts:138

What a parsed predicate, modifier or provider evaluates against. Reading a parameter the declared context key set does not provide reports a diagnostic and yields undefined, so a predicate attached to the wrong loot table fails loudly instead of quietly passing.

Constructors ​

Constructor ​

new PredicateContext(options?): PredicateContext

Defined in: context.ts:149

Parameters ​

options? ​

PredicateContextOptions = {}

Returns ​

PredicateContext

Properties ​

content ​

readonly content: ContentView

Defined in: context.ts:147


diagnostics ​

readonly diagnostics: DiagnosticCollector

Defined in: context.ts:144


enchantments ​

readonly enchantments: EnchantmentView

Defined in: context.ts:146


items ​

readonly items: ItemStackOps

Defined in: context.ts:145


level ​

readonly level: LevelView | undefined

Defined in: context.ts:143


parameters ​

readonly parameters: LootContextParameters

Defined in: context.ts:141


parameterSet ​

readonly parameterSet: "chest" | "empty" | "generic" | "command" | "command_slot_source" | "command_compute_default" | "command_compute_position" | "command_compute_entity" | "selector" | "villager_trade" | "fishing" | "entity" | "equipment" | "archaeology" | "gift" | "barter" | "vault" | "advancement_reward" | "advancement_entity" | "advancement_location" | "block_use" | "block" | "shearing" | "entity_interact" | "block_interact" | "container_process" | "enchanted_damage" | "enchanted_item" | "enchanted_location" | "enchanted_entity" | "hit_block"

Defined in: context.ts:140

The context key set the host declared, which decides what parameter will answer.


random ​

readonly random: RandomSource

Defined in: context.ts:142

Methods ​

levelWith() ​

levelWith<K>(key, path): LevelView & Required<Pick<LevelView, K>> | undefined

Defined in: context.ts:186

Returns the level view narrowed so key is callable on it, or undefined after reporting that the host cannot answer that question.

Type Parameters ​

K ​

K extends keyof LevelView

Parameters ​

key ​

K

path ​

string

Returns ​

LevelView & Required<Pick<LevelView, K>> | undefined


parameter() ​

parameter<K>(key, path): LootContextParameters[K] | undefined

Defined in: context.ts:167

Reads a loot context parameter.

Type Parameters ​

K ​

K extends keyof LootContextParameters

Parameters ​

key ​

K

path ​

string

Diagnostic path of the grammar member asking for it.

Returns ​

LootContextParameters[K] | undefined

The value, or undefined after reporting when the set does not declare the parameter or a required parameter is missing.