🔍

Predicate

Introduction

Sandstone features fully-typed predicates. Like for all resources, you need to provide a name, which can include a namespace and folders. You then provide the definition of the loot table.

Syntax

Minimal

The minimal syntax for predicates is the following:
import { Predicate } from 'sandstone'

Predicate('predicate_name', {
  condition: '<condition type>',
  ...additionalProperties,
})
As you can see, you must provide the condition of the predicate. Depending on this condition, several properties will be available.

Example

notion image

Additional properties

Predicates do not have additional properties, however they have condition-dependant properties. All those can be found directly via autocompletion (as shown above), or by looking at the Minecraft wiki article on Predicates.

Usage with commands

Selectors

Predicates can be used inside selectors using the predicate property:
const myPredicate = Predicate(...)

// Select all players matching the predicate
const matchingSelector = Selector('@a', { predicate: myPredicate })

Execute if

Predicates can also be used with execute.if:
execute.if.predicate(myPredicate).run.say('I am matching the predicate!')

Conditions

Predicates can natively be used as conditions with 🔄If / Else / While :
_.if(myPredicate, () => {
  say('I am matching the predicate!')
})

_.if(_.not(myPredicate), () => {
  say('I am **not** matching the predicate!')
})