Skip to content

Getting Started

runtoolkit edited this page Apr 13, 2026 · 1 revision

Getting Started

Installation

No npm package yet. Copy src/ into your project and import directly.

import { Engine } from './src/index.js';

Or import individual modules:

import { TickLoop } from './src/tick.js';
import { EventBus }  from './src/event.js';

Requires: Node.js with ES module support ("type": "module" in your package.json).


Minimal Example

import { Engine } from './src/index.js';

const engine = new Engine({ debug: true });

// Tick channel — fires every 20 ticks
engine.tick.register('heartbeat', (tick) => {
  console.log('tick:', tick);
}, { rate: 20 });

// Event handler
engine.events.register('player_join', ({ name }) => {
  console.log(`${name} joined`);
});

engine.events.fire('player_join', { name: 'Alice' });

engine.start();

Core Concepts

Tick pipelineTickLoop drives everything. Each registered channel declares its own rate (every N ticks), offset, and optional condition. The Engine wires Queue, EventBus, and CommandSystem flush into the tick automatically.

Events vs HooksEventBus is for arbitrary named events you define. HookSystem is for a fixed set of lifecycle events (player join, block break, etc.) where multiple plugins bind by ID.

CommandsCommandSystem parses string input, resolves the name against the registry, and calls the registered handler. Nothing reaches eval or the shell.

Fibers — Cooperative coroutines via async generators. A fiber yields control and waits to be resumed externally or after a timer.

State / Flags / Cooldowns — All keyed by (entity, key) pairs. Designed for per-player or per-entity data.

Clone this wiki locally