package dev.sillyangel.nuggetmod;

import com.mojang.logging.LogUtils;
import dev.sillyangel.nuggetmod.villager.ModVillagers;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.listener.SubscribeEvent;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.slf4j.Logger;
import dev.sillyangel.nuggetmod.item.ModCreativeModeTabs;
import dev.sillyangel.nuggetmod.item.ModItems;
import dev.sillyangel.nuggetmod.block.ModBlocks;
import dev.sillyangel.nuggetmod.sound.ModSounds;

// Very important Comment
// The value here should match an entry in the META-INF/mods.toml file
@Mod(NuggetMod.MOD_ID)
public class NuggetMod {
    // Define mod id in a common place for everything to reference
    public static final String MOD_ID = "nuggetmod";
    // Directly reference a slf4j logger
    public static final Logger LOGGER = LogUtils.getLogger();

    public NuggetMod(FMLJavaModLoadingContext context) {
        var modBusGroup = context.getModBusGroup();

        // Register the commonSetup method for modloading
        FMLCommonSetupEvent.getBus(modBusGroup).addListener(this::commonSetup);

        // Register the Deferred Register to the mod event bus so blocks get registered
        ModBlocks.register(modBusGroup);
        // Register the Deferred Register to the mod event bus so items get registered
        ModItems.register(modBusGroup);
        // Register the Deferred Register to the mod event bus so tabs get registered
        ModCreativeModeTabs.register(modBusGroup);
        // Register the Deferred Register to the mod event bus so sounds get registered
        ModSounds.register(modBusGroup);
        //
        ModVillagers.register(modBusGroup);
        // Register the item to a creative tab
        BuildCreativeModeTabContentsEvent.BUS.addListener(this::addCreative);

        // Register our mod's ForgeConfigSpec so that Forge can create and load the config file for us
        context.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
    }

    private void commonSetup(final FMLCommonSetupEvent event)  {

    }

    // Add the example block item to the building blocks tab
    private void addCreative(BuildCreativeModeTabContentsEvent event) {

    }

    // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
    @Mod.EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT)
    public static class ClientModEvents {
        @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event) {

        }
    }
}