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

Loot tables ​

A LootTableDef is a list of LootPools with weighted entries.

ts
dp.lootTable("chests/reward", new LootTableDef("chest").pool(new LootPool().item(Item.DIAMOND)));

Make a table ​

An item's count and components become loot functions for you.

ts
import { Datapack, v26_2, Item, LootTableDef, LootPool } from "helix";

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

dp.lootTable(
  "chests/reward",
  new LootTableDef("chest").pool(
    new LootPool()
      .rolls(1)
      .item(Item.DIAMOND.count(3), { weight: 1 })
      .item(Item.GOLDEN_APPLE.named("Prize"), { weight: 3 })
      .empty(2),
  ),
);

Open in playground

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

json
{
  "type": "minecraft:chest",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:diamond",
          "weight": 1,
          "functions": [
            {
              "function": "minecraft:set_count",
              "count": 3
            }
          ]
        },
        {
          "type": "minecraft:item",
          "name": "minecraft:golden_apple",
          "weight": 3,
          "functions": [
            {
              "function": "minecraft:set_components",
              "components": {
                "minecraft:custom_name": {
                  "text": "Prize"
                }
              }
            }
          ]
        },
        {
          "type": "minecraft:empty",
          "weight": 2
        }
      ]
    }
  ]
}
txt
{
  "pack": {
    "description": "loot\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

dp.lootTable returns a ref for /loot, set_loot or pool.lootTable(ref).

Add loot functions ​

.func(...) on a pool or entry adds a function. LootFunction.of takes any vanilla one, typed from the game schema.

ts
LootFunction.of("set_name", { name: text("Boss Loot"), target: "item_name" });
LootFunction.of("apply_bonus", { enchantment: Enchantment.FORTUNE, formula: "ore_drops" });

LootFunction.raw(id, fields) takes a non-vanilla function as JSON.

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.