Appearance
Selectors
A Selector is a typed @a/@e/@s/@p/@r with chained filters.
ts
const it = Selector.allPlayers().tag("it").limit(1);| Start from | Base |
|---|---|
Selector.allPlayers() | @a |
Selector.allEntities() | @e |
Selector.self() | @s |
Selector.nearest() | @p |
Selector.random() | @r |
Selector.uuid(id) | UUID/name |
| Filter | Selector arg |
|---|---|
.tag(name) | tag= (repeatable) |
.limit(n) / .sort(order) | limit= / sort= |
.distance(range) | distance= |
.score(objective, range) | scores={...} |
.gamemode(mode) | gamemode= |
.team(name) / .name(name) | team= / name= |
.nbt(nbt) | nbt={...} |
.predicate(ref) | predicate= (repeatable) |
.volume(from, to) | x/y/z + dx/dy/dz |
.xRotation(range) / .yRotation(range) | x_rotation= / y_rotation= |
Filter targets
new Range(min, max) leaves an end open with undefined: new Range(undefined, 8) is ..8.
ts
import { Datapack, v26_2, Selector, Range, Gamemode, Sort } from "helix";
const dp = new Datapack("targets", v26_2);
const game = dp.objective("game");
dp.createFunction("reward_nearby").build((ctx) => {
const winners = Selector.allPlayers()
.gamemode(Gamemode.SURVIVAL)
.distance(new Range(undefined, 8))
.score(game, new Range(10, undefined))
.sort(Sort.NEAREST)
.limit(3);
ctx.tellraw(winners, "you're close enough to win");
});Compiled output - the real files helix emits for the code above:
txt
tellraw @a[scores={game=10..},distance=..8,gamemode=survival,limit=3,sort=nearest] {"text":"you're close enough to win"}txt
{
"pack": {
"description": "targets\nCreated using Helix",
"min_format": [
107,
1
],
"max_format": [
107,
1
]
}
}WARNING
Filters change the selector in place. Don't reuse one selector variable for two different targets.
Run something per match
sel.forEach(body) runs body as and at each match.
ts
import { Datapack, v26_2, Selector, EntityType } from "helix";
const dp = new Datapack("targets", v26_2);
dp.createFunction("warn_creepers").build(() => {
Selector.allEntities()
.type(EntityType.CREEPER)
.forEach((c) => c.say("hiss"));
});Compiled output - the real files helix emits for the code above:
txt
execute as @e[type=minecraft:creeper] at @s run say hisstxt
{
"pack": {
"description": "targets\nCreated using Helix",
"min_format": [
107,
1
],
"max_format": [
107,
1
]
}
}Check NBT cheaply
Register a check once with dp.predicate(...) and use .predicate(ref) instead of a large .nbt(...).
See also
- Helpers:
on,killWithPassengers,slot, ... - Execute chains
- Data resources: predicates