Appearance
Supply drop
A function that drops a chest and fills it from one of three loot tiers, picked at random by weight.
| Technique | Where |
|---|---|
| Loot tables | loot.ts: three LootTableDefs; rare and epic nest the tier below with lootTable(...) |
| Random rolls | loot.ts: rolls({ min, max }) renders as a uniform number provider for the target version |
| Weighted pick | main.ts: ctx.pick rolls once and runs one case: 6 : 3 : 1 |
| Items in loot | loot.ts: named, enchanted items become set_components in the table, the same as in give |
| Inline effects | main.ts: the epic case adds particles and a broadcast alongside the loot |
ts
import { Selector, Pos, Block, Particle, text, Color } from "helix";
import { dp } from "./pack";
import { common, rare, epic } from "./loot";
// Drops a chest above the player and fills it from a random tier: 6 : 3 : 1.
dp.public("drop").build((ctx) => {
const spot = Pos.rel(0, 1, 0);
ctx.setblock(spot, Block.CHEST);
ctx.pick([
[6, (c) => c.loot().insertLoot(spot, common)],
[3, (c) => c.loot().insertLoot(spot, rare)],
[1, (c) => {
c.loot().insertLoot(spot, epic);
c.particle(Particle.TOTEM_OF_UNDYING, { at: spot, spread: [0.5, 1, 0.5], count: 40 });
c.tellraw(Selector.allPlayers(), text("An epic supply drop has landed!").color(Color.GOLD).bold());
}],
]);
});ts
import { Datapack, v26_3 } from "helix";
export const dp = new Datapack("drops", v26_3);ts
import { Item, Enchantment, LootTableDef, LootPool, LootFunction, text, Color } from "helix";
import { dp } from "./pack";
// Three tiers of chest loot; rare and epic roll the tier below too.
export const common = dp.lootTable("tier/common", new LootTableDef("chest").pool(
new LootPool()
.rolls({ min: 3, max: 5 })
.item(Item.BREAD.count(4), { weight: 4 })
.item(Item.ARROW.count(16), { weight: 3 })
.item(Item.IRON_INGOT, { weight: 2 })
.empty(2),
));
export const rare = dp.lootTable("tier/rare", new LootTableDef("chest")
.pool(new LootPool().rolls(2).lootTable(common))
.pool(
new LootPool()
.rolls(1)
.item(Item.DIAMOND.count(2), { weight: 2 })
.item(Item.IRON_SWORD, { functions: [LootFunction.enchantWithLevels(20)] }),
),
);
export const epic = dp.lootTable("tier/epic", new LootTableDef("chest")
.pool(new LootPool().rolls(1).lootTable(rare))
.pool(
new LootPool().rolls(1).item(
Item.NETHERITE_SWORD.named(text("Dropbreaker").color(Color.GOLD))
.enchant(Enchantment.SHARPNESS, 5)
.lore("Fell from the sky"),
),
),
);Compiled output - the real files helix emits for the code above:
txt
loot insert ~ ~1 ~ loot drops:tier/epic
particle minecraft:totem_of_undying ~ ~1 ~ 0.5 1 0.5 0 40
tellraw @a {"text":"An epic supply drop has landed!","color":"gold","bold":true}txt
setblock ~ ~1 ~ minecraft:chest
execute store result score #drop.0 helix.var run random value 0..9
execute if score #drop.0 helix.var matches 0..5 run return run loot insert ~ ~1 ~ loot drops:tier/common
execute if score #drop.0 helix.var matches 6..8 run return run loot insert ~ ~1 ~ loot drops:tier/rare
execute if score #drop.0 helix.var matches 9 run return run function drops:zzzprivate/drop/exec_0/exec_3/return_0json
{
"type": "minecraft:chest",
"pools": [
{
"rolls": {
"type": "minecraft:uniform",
"min": 3,
"max": 5
},
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:bread",
"weight": 4,
"modifier": {
"type": "minecraft:set_count",
"count": 4
}
},
{
"type": "minecraft:item",
"name": "minecraft:arrow",
"weight": 3,
"modifier": {
"type": "minecraft:set_count",
"count": 16
}
},
{
"type": "minecraft:item",
"name": "minecraft:iron_ingot",
"weight": 2
},
{
"type": "minecraft:empty",
"weight": 2
}
]
}
]
}json
{
"type": "minecraft:chest",
"pools": [
{
"rolls": 2,
"entries": [
{
"type": "minecraft:loot_table",
"value": "drops:tier/common"
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:diamond",
"weight": 2,
"modifier": {
"type": "minecraft:set_count",
"count": 2
}
},
{
"type": "minecraft:item",
"name": "minecraft:iron_sword",
"modifier": {
"type": "minecraft:enchant_with_levels",
"levels": 20
}
}
]
}
]
}json
{
"type": "minecraft:chest",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"value": "drops:tier/rare"
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:netherite_sword",
"modifier": {
"type": "minecraft:set_components",
"components": {
"minecraft:custom_name": {
"text": "Dropbreaker",
"color": "gold"
},
"minecraft:enchantments": {
"minecraft:sharpness": 5
},
"minecraft:lore": [
{
"text": "Fell from the sky"
}
]
}
}
}
]
}
]
}txt
{
"pack": {
"description": "drops\nCreated using Helix",
"min_format": [
121,
0
],
"max_format": [
121,
0
]
}
}Try it
Run /function drops:drop.