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

Smite wand ​

Right-click a custom stick to fire a ray that stops at the first block or undead mob, then damages undead near the impact, with a cooldown.

TechniqueWhere
Advancement eventmain.ts: dp.event + Trigger.usingItem, no tick polling
Usable custom itemwand.ts: consumable makes the stick usable; customData + matchByData stop plain sticks matching
Raycast loopcast.ts: ctx.while steps half a block forward from the eyes; .else runs at the hit point
Per-player cooldownmain.ts: cooldown.countDown() in tick; the event checks it before casting
ts
import { Selector, Trigger, text, Color, Component } from "helix";
import { dp } from "./pack";
import { wand } from "./wand";
import { cast } from "./cast";

const cooldown = dp.objective("wand_cd").score(Selector.self());

dp.event("use_wand", Trigger.usingItem(wand), (ctx) => {
  ctx
    .if(cooldown.greaterThan(0), (c) =>
      c.title().actionbar(Selector.self(), Component(text("Recharging...").color(Color.GRAY))),
    )
    .else((c) => {
      cooldown.set(30);
      c.call(cast);
    });
});

dp.tick(() => {
  Selector.allPlayers().forEach(() => cooldown.countDown());
});
ts
import { Datapack, v26_3 } from "helix";

export const dp = new Datapack("wand", v26_3);
ts
import { Selector, Item, ItemUseAnimation, text, Color } from "helix";
import { dp } from "./pack";

// A long use time, so holding right-click keeps the wand in use.
export const wand = Item.STICK.named(text("Smite Wand").color(Color.LIGHT_PURPLE))
  .lore("Right-click to cast")
  .consumable({ consumeSeconds: 100000, animation: ItemUseAnimation.BOW, hasConsumeParticles: false })
  .customData({ smite_wand: true })
  .matchByData();

dp.public("give").build((ctx) => ctx.playerGive(Selector.self(), wand));
ts
import { Selector, Detect, Pos, Block, BLOCK_TAGS, EntityAnchor, EntityType, ENTITY_TYPE_TAGS, Particle, Range, Dust, and } from "helix";
import { dp } from "./pack";

const undead = EntityType.tag(ENTITY_TYPE_TAGS.UNDEAD);

// Step forward through air until the ray reaches a block or an undead mob (24 blocks max).
export const cast = dp.createFunction("cast").build((ctx) => {
  const inAir = Detect.block(Pos.here(), Block.tag(BLOCK_TAGS.AIR));
  const noUndeadHere = Detect.noEntity(Selector.allEntities().type(undead).distance(Range.atMost(1)));

  ctx.execute().anchored(EntityAnchor.EYES).positioned(Pos.local(0, 0, 0)).run((c) => {
    c.while(
      and(inAir, noUndeadHere),
      (step) => step.particle(Dust(0xff55ff, 0.8), { count: 1 }),
      { advance: (e) => e.positioned(Pos.local(0, 0, 0.5)), max: 48 },
    ).else((hit) => {
      hit.particle(Particle.EXPLOSION, { count: 1 });
      Selector.allEntities().type(undead).distance(Range.atMost(2)).forEach((mob) => {
        mob.damage(Selector.self(), 8);
      });
    });
  });
});

Open in playground

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

txt
give @s minecraft:stick[custom_name={"text":"Smite Wand","color":"light_purple"},lore=[{"text":"Right-click to cast"}],consumable={consume_seconds:100000.0f,animation:"bow",has_consume_particles:false},custom_data={smite_wand:true}] 1
txt
particle minecraft:dust{color:[1.0f,0.3333f,1.0f],scale:0.8f} ~ ~ ~ 0 0 0 0 1
scoreboard players remove #zzzprivate/cast.0 helix.var 1
execute positioned ^ ^ ^0.5 run return run function wand:zzzprivate/cast/exec_0/while_0
txt
particle minecraft:explosion ~ ~ ~ 0 0 0 0 1
execute as @e[distance=..2,type=#minecraft:undead] at @s run damage @s 8
txt
execute if block ~ ~ ~ #minecraft:air unless entity @e[distance=..1,limit=1,type=#minecraft:undead] if score #zzzprivate/cast.0 helix.var matches 1.. run return run function wand:zzzprivate/cast/exec_0/while_0/pass_0
return run function wand:zzzprivate/cast/exec_0/while_0/else_0
txt
scoreboard players set #zzzprivate/cast.0 helix.var 48
function wand:zzzprivate/cast/exec_0/while_0
txt
advancement revoke @s only wand:zzzprivate/use_wand
execute if score @s wand_cd matches 1.. run return run title @s actionbar {"text":"Recharging...","color":"gray"}
scoreboard players set @s wand_cd 30
execute anchored eyes positioned ^ ^ ^ run function wand:zzzprivate/cast/exec_0
txt
execute as @a at @s if score @s wand_cd matches 1.. run scoreboard players remove @s wand_cd 1
json
{
  "values": [
    "wand:tick"
  ]
}
json
{
  "criteria": {
    "trigger": {
      "trigger": "minecraft:using_item",
      "conditions": {
        "item": {
          "items": "minecraft:stick",
          "predicates": {
            "minecraft:custom_data": "{smite_wand:true}"
          }
        }
      }
    }
  },
  "rewards": {
    "function": "wand:zzzprivate/use_wand"
  }
}
txt
{
  "pack": {
    "description": "wand\nCreated using Helix",
    "min_format": [
      121,
      0
    ],
    "max_format": [
      121,
      0
    ]
  }
}

Try it

Run /function wand:give, then hold right-click.

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