Skip to content

helix / Predicate

Class: Predicate

Defined in: core/values/predicate.ts:156

A composable Minecraft predicate condition tree. Renders to the JSON written into data/<ns>/<predicate folder>/<name>.json (via Datapack.predicate) and referenced by id from @e[predicate=...] (Selector.predicate) or execute if predicate ... (predicateCheck).

The point: express an entity-state check - including NBT - once, as a typed, referenceable, engine-evaluated predicate, instead of inlining nbt={...} into every selector. Predicate.entity({ nbt }) is the "over NBT" path.

const sleeping = dp.predicate("sleeping", Predicate.entity({ nbt: Nbt({ SleepTimer: Short(100) }) })); Selector.allPlayers().predicate(sleeping) // @a[predicate=ns:sleeping]

Methods

and()

and(...terms): Predicate

Defined in: core/values/predicate.ts:285

This predicate AND-ed with more terms.

Parameters

terms

...Predicate[]

Returns

Predicate


not()

not(): Predicate

Defined in: core/values/predicate.ts:280

This predicate inverted.

Returns

Predicate


or()

or(...terms): Predicate

Defined in: core/values/predicate.ts:290

This predicate OR-ed with more terms.

Parameters

terms

...Predicate[]

Returns

Predicate


toJson()

toJson(version): PredicateJson

Defined in: core/values/predicate.ts:160

The condition JSON for this predicate, with embedded values rendered for version.

Parameters

version

VersionProfile

Returns

PredicateJson


all()

static all(...terms): Predicate

Defined in: core/values/predicate.ts:259

all_of - passes only if every term passes (logical AND).

Parameters

terms

...Predicate[]

Returns

Predicate


any()

static any(...terms): Predicate

Defined in: core/values/predicate.ts:267

any_of - passes if any term passes (logical OR).

Parameters

terms

...Predicate[]

Returns

Predicate


blockState()

static blockState(block, properties?): Predicate

Defined in: core/values/predicate.ts:187

block_state_property - the block being checked plus optional blockstate values.

Parameters

block

string | BlockValue

properties?

Record<string, string>

Returns

Predicate


entity()

static entity(spec, who?): Predicate

Defined in: core/values/predicate.ts:167

entity_properties - match who (default the looked-at entity) against typed properties.

Parameters

spec

EntityPredicateSpec

who?

EntityTarget = "this"

Returns

Predicate


holding()

static holding(item, slot?, who?): Predicate

Defined in: core/values/predicate.ts:226

entity_properties matching an entity carrying item in slot (default mainhand - a player's selected hotbar item). The engine-evaluated, referenceable replacement for an inline nbt={SelectedItem:{id:...}} scan; built from the same ItemValue you'd give, via its toPredicate(...).

Parameters

item

ItemValue

slot?

keyof EquipmentSpec = "mainhand"

who?

EntityTarget = "this"

Returns

Predicate


location()

static location(spec): Predicate

Defined in: core/values/predicate.ts:199

location_check - facts about the location being evaluated.

Parameters

spec

LocationSpec

Returns

Predicate


matchTool()

static matchTool(item): Predicate

Defined in: core/values/predicate.ts:213

match_tool - passes when the item being used/checked matches item. Built from the same ItemValue you'd give, via its toPredicate(...), so there is exactly one definition of the item. (Note: match_tool is evaluated against the tool in loot/mining contexts; for held-item checks on an entity use Selector.holding(item).)

Parameters

item

ItemValue

Returns

Predicate


not()

static not(term): Predicate

Defined in: core/values/predicate.ts:275

inverted - passes iff term fails (logical NOT).

Parameters

term

Predicate

Returns

Predicate


randomChance()

static randomChance(chance): Predicate

Defined in: core/values/predicate.ts:245

random_chance - passes with probability chance (0..1).

Parameters

chance

number

Returns

Predicate


reference()

static reference(ref): Predicate

Defined in: core/values/predicate.ts:250

reference - defer to another predicate by id.

Parameters

ref

string | IdValue | PredicateRef

Returns

Predicate


scores()

static scores(scores, who?): Predicate

Defined in: core/values/predicate.ts:176

entity_scores - objective bounds on who's scores.

Parameters

scores

Record<string, ScoreBound>

who?

EntityTarget = "this"

Returns

Predicate


weather()

static weather(spec): Predicate

Defined in: core/values/predicate.ts:235

weather_check.

Parameters

spec
raining?

boolean

thundering?

boolean

Returns

Predicate

Released under the MIT License · Credits