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.
2020-05-03 23:28:23 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 00:32:43 +00:00
|
|
|
addBridge('Event.tick', (world: JavaObject) => TickEvent.INSTANCE.run(new World(world)));
|