package top.r3944realms.lib39;

import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import top.r3944realms.lib39.core.network.NetworkHandler;
import top.r3944realms.lib39.core.register.NeoForgeLib39BlockEntities;
import top.r3944realms.lib39.core.register.NeoForgeLib39Blocks;
import top.r3944realms.lib39.core.register.NeoForgeLib39Items;
import top.r3944realms.lib39.core.register.NeoForgeLib39SoundEvents;
import top.r3944realms.lib39.example.NeoForgeLib39Example;

/**
 * The type Lib 39.
 */
@Mod(Lib39.MOD_ID)
public class Lib39NeoForge {
    /**
     * The constant modEventBus.
     */
    public static IEventBus modEventBus;

    /**
     * Instantiates a new Lib 39.
     *
     * @param modEventBus the mod event bus
     */
    public Lib39NeoForge(IEventBus modEventBus) {
        Lib39.initialize();
        if(this.modEventBus == null) {
            this.modEventBus = modEventBus;
        }
        initialize(modEventBus);
    }

    /**
     * Initialize.
     *
     * @param modEventBus the mod event bus
     */
    public static void initialize(IEventBus modEventBus) {
        Lib39.LOGGER.info("[Lib39-NeoForge] Hello NeoForge");
        NeoForgeLib39Blocks.register(modEventBus);
        NeoForgeLib39Items.register(modEventBus);
        NeoForgeLib39BlockEntities.register(modEventBus);
        NeoForgeLib39SoundEvents.register(modEventBus);
        if (Lib39.shouldRegisterExamples()) {
            Lib39.LOGGER.info("[Lib39-NeoForge] Registering Examples");
            registerExamples(modEventBus);
        }
        Lib39.LOGGER.info("[Lib39-NeoForge] Finished Initializing.");

    }

    /**
     * Register examples.
     *
     * @param modEventBus the mod event bus
     */
    static void registerExamples(IEventBus modEventBus) {
        Lib39.LOGGER.info("[Lib39-NeoForge] Starting example demonstrations");
        try {
            // 创建示例实例并演示功能
            NeoForgeLib39Example example = new NeoForgeLib39Example(modEventBus);
            example.demonstrateFeature();

            Lib39.LOGGER.info("[Lib39-NeoForge] Example demonstrations completed successfully");
        } catch (Exception e) {
            Lib39.LOGGER.error("[Lib39-NeoForge] Failed to demonstrate examples", e);
        }
    }
}
