Alpha: this compiler is under active development and updates will break your projects. Not recommended for real use yet.
Skip to content

Predicates ​

A Predicate is a reusable condition file the game checks itself, cheaper than a large nbt={...} in a selector.

ts
const sneaking = dp.predicate("sneaking", Predicate.entity({ flags: { is_sneaking: true } }));
BuilderChecks
Predicate.entity({...})entity state and NBT
Predicate.scores({...})scores
Predicate.holding(item, slot?)an equipment slot
Predicate.matchTool(item)the tool (loot context)
Predicate.blockState / .location / .weatherworld state
Predicate.randomChance(p)a random roll
.and / .or / .notcombinations
Predicate.of(id, args)any vanilla condition

Make and use one ​

Use the ref in Selector.predicate(ref) or ctx.if(predicateCheck(ref), ...).

ts
import { Datapack, v26_2, Selector, Predicate, Nbt, Short } from "helix";

const dp = new Datapack("checks", v26_2);

const focused = dp.predicate(
  "focused",
  Predicate.entity({
    flags: { is_sneaking: true },
    nbt: Nbt({ SleepTimer: Short(0) }),
  }).and(Predicate.scores({ combo: { min: 3 } })),
);

dp.createFunction("reward").build((ctx) => {
  ctx.tellraw(Selector.allPlayers().predicate(focused), "focused bonus!");
});

Open in playground

Compiled output - the real files helix emits for the code above:

txt
tellraw @a[predicate=checks:focused] {"text":"focused bonus!"}
json
{
  "condition": "minecraft:all_of",
  "terms": [
    {
      "condition": "minecraft:entity_properties",
      "entity": "this",
      "predicate": {
        "nbt": "{SleepTimer:0s}",
        "flags": {
          "is_sneaking": true
        }
      }
    },
    {
      "condition": "minecraft:entity_scores",
      "entity": "this",
      "scores": {
        "combo": {
          "min": 3
        }
      }
    }
  ]
}
txt
{
  "pack": {
    "description": "checks\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

Check what a player holds ​

Predicate.holding takes the same Item you gave, so it always matches it.

ts
import { Datapack, v26_2, Selector, Item, Enchantment, Predicate } from "helix";

const dp = new Datapack("checks", v26_2);
const wand = Item.STICK.named("Wand").enchant(Enchantment.KNOCKBACK, 1);
const holdingWand = dp.predicate("holding_wand", Predicate.holding(wand));

dp.createFunction("cast").build((ctx) => {
  ctx.tellraw(Selector.allPlayers().predicate(holdingWand), "you feel a spark");
});

Open in playground

Compiled output - the real files helix emits for the code above:

txt
tellraw @a[predicate=checks:holding_wand] {"text":"you feel a spark"}
json
{
  "condition": "minecraft:entity_properties",
  "entity": "this",
  "predicate": {
    "equipment": {
      "mainhand": {
        "items": "minecraft:stick",
        "components": {
          "minecraft:custom_name": {
            "text": "Wand"
          },
          "minecraft:enchantments": {
            "minecraft:knockback": 1
          }
        }
      }
    }
  }
}
txt
{
  "pack": {
    "description": "checks\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

See also ​

Released under the MIT License · Credits
These docs were written with AI; the layout and every page have been reviewed by a human.