package com.r3944realms.modernlifepatch;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraftforge.event.AddPackFindersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.forgespi.locating.IModFile;
import net.minecraftforge.resource.PathPackResources;

import java.nio.file.Path;

import static com.r3944realms.modernlifepatch.datagen.lang.ModLangKeyValue.MOD_RESOURCE_NAME;

public abstract class CommonEventHandler {
//    @net.minecraftforge.fml.common.Mod.EventBusSubscriber(bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.FORGE, modid = ModernLifePatch.MOD_ID)
    public static class Game extends CommonEventHandler {

    }
    @net.minecraftforge.fml.common.Mod.EventBusSubscriber(bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.MOD, modid = ModernLifePatch.MOD_ID)
    public static class Mod extends CommonEventHandler {
        @SubscribeEvent
        public static void onCommonSetup(FMLCommonSetupEvent event) {
            event.enqueueWork(() -> {

            });
        }
        @SubscribeEvent
        public static void onRegisterResourcePack(AddPackFindersEvent event) {
            IModFile modFile = ModList.get().getModFileById(ModernLifePatch.MOD_ID).getFile();
            Path modFilePath = modFile.findResource("resourcepacks/modernlifepatch");
            event.addRepositorySource(consumer -> {
                Pack pack = Pack.readMetaAndCreate(
                        new ResourceLocation(ModernLifePatch.MOD_ID, "modernlifepatch").toString(),
                        Component.translatable(MOD_RESOURCE_NAME.getKey()),
                        true,
                        name -> new PathPackResources(name, true, modFilePath),
                        PackType.CLIENT_RESOURCES,
                        Pack.Position.TOP,
                        PackSource.BUILT_IN
                );
                if(pack != null) consumer.accept(pack);
            });
        }
    }
}
