This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ScriptCraft/src/main/ts/src/minecraft/event.ts

36 lines
723 B
TypeScript

import { World } from './world';
import { addBridge } from 'scriptcraft-core';
/**
* Tick Event
*/
export class TickEvent {
/**
* Instance
*/
static INSTANCE: TickEvent = new TickEvent();
/**
* @internal
*/
#listeners: ((world: World) => void)[];
/**
* Add Event Listener
* @param listener Event Listener
*/
addListener(listener: (world: World) => void): void {
this.#listeners.push(listener);
}
/**
* @internal
*/
run(world: World): void {
for (const listener of this.#listeners) {
listener(world);
}
}
}
addBridge('Event.tick', (world: JavaObject) => TickEvent.INSTANCE.run(new World(world)));