Skip to content

twine / DatapackModule

Interface: DatapackModule

Defined in: module.interface.ts:14

A datapack module is a class with an optional constructor and the lifecycle hooks below. It is instantiated once by DatapackFactory when its containing module tree is enabled (i.e. it is reachable through the root module's imports). A module NOT reachable through imports is never constructed and emits nothing - that is the compile-time disable.

Methods

onActivate()?

optional onActivate(ctx): void

Defined in: module.interface.ts:41

Runs once when this module's area becomes active (see ModuleMetadata.area) - e.g. summon a level's entities. Only meaningful on an area module; emitted into its generated <name>/activate function.

Parameters

ctx

FunctionContext

Returns

void


onDeactivate()?

optional onDeactivate(ctx): void

Defined in: module.interface.ts:47

Runs once when this module's area becomes inactive - e.g. despawn the level's entities and clean up. Emitted into <name>/deactivate.

Parameters

ctx

FunctionContext

Returns

void


onLoad()?

optional onLoad(ctx): void

Defined in: module.interface.ts:25

Appended to the shared load function (runs on pack load / /reload). Always runs - load-time setup is not gated by the runtime flag.

Parameters

ctx

FunctionContext

Returns

void


onTick()?

optional onTick(ctx): void

Defined in: module.interface.ts:34

Appended to the shared tick function (runs every game tick) - but only reached while every area ancestor of this module is active. Put per-tick work here (proximity checks, timers); it costs nothing while an ancestor area is inactive, because the parent's single active check skips the whole subtree before this is ever called.

Parameters

ctx

FunctionContext

Returns

void


register()?

optional register(dp): void

Defined in: module.interface.ts:19

Arbitrary one-off setup: declare extra objectives, create standalone functions, register structures, etc. Runs once at build time.

Parameters

dp

Datapack

Returns

void

Released under the MIT License · Credits