This commit is contained in:
parent
82b00bdaec
commit
0a3883513e
@ -1,6 +1,7 @@
|
||||
package com.thebrokenrail.scriptcraft.api;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.api.bridge.Bridges;
|
||||
import com.thebrokenrail.scriptcraft.api.event.Events;
|
||||
import com.thebrokenrail.scriptcraft.core.ScriptCraftEntrypoint;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ -22,5 +23,6 @@ public class ScriptCraftAPI implements ScriptCraftEntrypoint {
|
||||
|
||||
static {
|
||||
Bridges.init();
|
||||
Events.init();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.thebrokenrail.scriptcraft.api.event;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
|
||||
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
|
||||
|
||||
public class Events {
|
||||
public static void init() {
|
||||
WorldTickCallback.EVENT.register(world -> ScriptCraftCore.useBridge("TickEvent.run", world));
|
||||
}
|
||||
}
|
35
src/main/ts/src/minecraft/event.ts
Normal file
35
src/main/ts/src/minecraft/event.ts
Normal file
@ -0,0 +1,35 @@
|
||||
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('TickEvent.run', (world: JavaObject) => TickEvent.INSTANCE.run(new World(world)));
|
@ -16,3 +16,4 @@ export { LivingEntity, PlayerEntity } from './entity';
|
||||
export { CompoundTag, ListTag, NumberType } from './tag';
|
||||
export { Registry } from './registry';
|
||||
export { Inventory } from './inventory';
|
||||
export { TickEvent } from './event';
|
||||
|
Reference in New Issue
Block a user