Appearance
Twine - the framework
twine structures a whole pack as a tree of modules with lifecycle hooks and areas that switch features on and off.
ts
@Module({ name: "courtyard", area: true, imports: [FrostWand] })
export class CourtyardArea {
onTick(ctx: FunctionContext) {}
}
const dp = DatapackFactory.create(RootModule, opts);Define a module
@Module({ name, area?, activeByDefault?, imports?, env? }) marks a class as a module. Modules not reachable through imports emit nothing.
| Hook | Runs |
|---|---|
register(dp) | once at build time |
onLoad(ctx) | on load |
onTick(ctx) | each tick, while every parent area is on |
onActivate(ctx) / onDeactivate(ctx) | when an area turns on / off |
An area: true module skips its whole subtree's tick with one check while inactive. twine routes all tick work through one minecraft:tick entry.
Add custom items
An item is an empty class with a decorator. Pass the class anywhere helix takes an item.
ts
@Upgrade({ name: "scope", look: "minecraft:spyglass", label: "Scope", lore: "Zoom", effects: {...} })
export class Scope {}
@CustomItem({ name: "crossbow", item: Item.CROSSBOW, upgrades: { 2: Scope } })
export class CrossbowItem {}
ctx.playerGive(sel, withUpgrades(CrossbowItem, Scope));Behaviour goes in a module as a handler, gated by that module's area:
ts
@Module({ name: "courtyard", area: true, imports: [FrostWand] })
export class CourtyardArea {
@OnUse(FrostWand)
glow(ctx: FunctionContext) {
ctx.effect().give(ctx.self, MobEffect.GLOWING, 5);
}
}Every item gets a public <name>/give function. @Bench defines an upgrade bench.
Track entity state
StateMachine gives an entity or player explicit states and transitions, backed by scores.