import { world, system } from '@minecraft/server';
import { BasicGrowthRecipeListener, SaplingGrowthRecipeListener, TwoByTwoSaplingGrowthRecipeListener } from './types.js';
import { sieves as U } from '../ftb_bedrock_bedrock_utils_dist_bedrock_utils.js';

const API_LISTENERS = [
    new BasicGrowthRecipeListener(),
    new SaplingGrowthRecipeListener(),
    new TwoByTwoSaplingGrowthRecipeListener()
];
world.afterEvents.worldLoad.subscribe(event => {
    system.sendScriptEvent(U("register_init"), "");
});
system.afterEvents.scriptEventReceive.subscribe((event) => {
    for (const listener of API_LISTENERS) {
        if (event?.id === listener.id) {
            try {
                const message = listener.parseMessage(event.message);
                listener.callback(message);
            }
            catch (e) {
                console.error(`Error processing event for listener ${listener.id}:`, e);
            }
        }
    }
});
