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

Helpers ​

Verbs that replace common hand-written execute chains, tags and score round trips.

Entities ​

HelperInstead ofEmits
ctx.summon(entity, pos, body)summoning with a x.new tag, then as @e[tag=x.new]execute positioned ... summon ... run, with the NBT merged
sel.forEach(body)execute as <sel> at @s run ...the same, in one line or one child function
sel.on(Relation.PASSENGERS, body)execute as <sel> on passengers run ...the same, with as dropped for ctx.self
sel.killWithPassengers()killing each layer of riders by handa function that kills riders first, all the way down
ctx.ref(target, (c, ref) => ...)tagging an entity so another context can find ittag add, the body, tag remove
ctx.summonIf(cond, display)execute unless entity ... run summon ...one guarded line
ctx.whenEntity(sel, body)an if entity on every lineone guarded line per command
ctx.whenPlayerNear(pos, r, body)execute positioned ... if entity @a[distance=..r]one guarded line per command
ctx.atEntity(sel, body, align?)execute at <sel> [align] run ...the same
sel.slot(s), sel.attribute(a), sel.postEffectsitem replace, attribute ... modifier, /posteffectthe matching command

The summon body runs as and at the new entity. Copy caller values into a local first.

WARNING

NBT is merged after spawning, so passengers can't be used with a body.

ts
import { Datapack, v26_3, Interaction, Pos, Relation, Selector, EntityType } from "helix";

const dp = new Datapack("helpers", v26_3);
const owner = dp.objective("owner");

dp.createFunction("place").build((ctx) => {
  const me = ctx.let(owner.score(ctx.self)); // a fake player, so the body still sees it
  ctx.summon(Interaction({ tags: ["box"] }), Pos.rel(0, 1, 0), (c) => {
    owner.score(c.self).assign(me);
  });
  Selector.allEntities()
    .type(EntityType.ARMOR_STAND)
    .tag("seat")
    .on(Relation.PASSENGERS, (p) => p.say("still riding"));
});

Open in playground

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

txt
data merge entity @s {Tags:["box"]}
scoreboard players operation @s owner = #zzzprivate/place.0 helix.var
txt
scoreboard players operation #zzzprivate/place.0 helix.var = @s owner
execute positioned ~ ~1 ~ summon minecraft:interaction run function helpers:zzzprivate/place/exec_0
execute as @e[tag=seat,type=minecraft:armor_stand] on passengers run say still riding
txt
{
  "pack": {
    "description": "helpers\nCreated using Helix",
    "min_format": [
      121,
      0
    ],
    "max_format": [
      121,
      0
    ]
  }
}

Scores and NBT ​

HelperInstead ofEmits
score.countDown()ctx.if(cd.atLeast(1), () => cd.remove(1))execute if score ... matches 1.. run ... remove
score.storeEntity(who, path, type, k?)execute store result entity ... <type> <1/scale> run ... getthe same, at the score's scale
score.readEntity(who, path)execute store result score ... run data get entity ... <scale>the same
view.set(score, type?)a store chain into storage, an entity or a blockthe same; a scaled score is stored as a double
StorageData<T>(storage).a.b.set(...)hand-typed NBT pathsdata modify ..., with the path checked by T
list.forEach((c, el) => ...)copying a list and looping over its head by handa copy in helix:each and a while loop
ctx.let(init?)picking a fake-player holder namea slot on helix.var

Control flow and time ​

HelperInstead ofEmits
ctx.if(c, ...).elif(...).else(...)return run chains, or a flag score per branchone execute per branch
ctx.cases([[cond, body], ...])a long elif chainthe same as if/elif
ctx.dispatchScore(score, ranges)one if score ... matches per valuea binary search past 8 cases
ctx.repeat(n, body), ctx.while(c, body)a recursive function by handa recursive function, or copies in place when the count is fixed and small
ctx.pick([[weight, body], ...])random value into a score, then rangesone roll and a dispatch
ctx.wait(time, body)a schedule plus a tag and a due-tick score per entityschedule ... append, with each entity waking on its own tick
dp.after(ctx, time, body)naming a function just to schedule itschedule function ... append, run as the server
dp.fn(name, (ctx, ...args) => result)copying arguments into fixed score namesa function with score parameters

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.