Appearance
Helpers
Verbs that replace common hand-written execute chains, tags and score round trips.
Entities
| Helper | Instead of | Emits |
|---|---|---|
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 hand | a function that kills riders first, all the way down |
ctx.ref(target, (c, ref) => ...) | tagging an entity so another context can find it | tag 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 line | one 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.postEffects | item replace, attribute ... modifier, /posteffect | the 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"));
});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.vartxt
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 ridingtxt
{
"pack": {
"description": "helpers\nCreated using Helix",
"min_format": [
121,
0
],
"max_format": [
121,
0
]
}
}Scores and NBT
| Helper | Instead of | Emits |
|---|---|---|
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 ... get | the 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 block | the same; a scaled score is stored as a double |
StorageData<T>(storage).a.b.set(...) | hand-typed NBT paths | data modify ..., with the path checked by T |
list.forEach((c, el) => ...) | copying a list and looping over its head by hand | a copy in helix:each and a while loop |
ctx.let(init?) | picking a fake-player holder name | a slot on helix.var |
Control flow and time
| Helper | Instead of | Emits |
|---|---|---|
ctx.if(c, ...).elif(...).else(...) | return run chains, or a flag score per branch | one execute per branch |
ctx.cases([[cond, body], ...]) | a long elif chain | the same as if/elif |
ctx.dispatchScore(score, ranges) | one if score ... matches per value | a binary search past 8 cases |
ctx.repeat(n, body), ctx.while(c, body) | a recursive function by hand | a recursive function, or copies in place when the count is fixed and small |
ctx.pick([[weight, body], ...]) | random value into a score, then ranges | one roll and a dispatch |
ctx.wait(time, body) | a schedule plus a tag and a due-tick score per entity | schedule ... append, with each entity waking on its own tick |
dp.after(ctx, time, body) | naming a function just to schedule it | schedule function ... append, run as the server |
dp.fn(name, (ctx, ...args) => result) | copying arguments into fixed score names | a function with score parameters |