package com.r3944realms.modernlifepatch.content.item;

import com.dairymoose.modernlife.core.CustomBlocks;
import com.r3944realms.modernlifepatch.ModernLifePatch;
import com.r3944realms.modernlifepatch.datagen.lang.ModLangKeyValue;
import com.r3944realms.modernlifepatch.modInterface.CreativeItem;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

public class ModCreativeTabs {
    private static final DeferredRegister<CreativeModeTab> CREATIVE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, ModernLifePatch.MOD_ID);
    public static final RegistryObject<CreativeModeTab> MAIN = CREATIVE_TABS.register("creative_tab", () -> CreativeModeTab.builder()
            .title(Component.translatable(ModLangKeyValue.CREATIVE_TAB_NAME.getKey()))
            .icon(() -> ModernLifePatch.isModernLifeLoaded ? CustomBlocks.ITEM_CAMERA.get().getDefaultInstance() : Blocks.BARRIER.asItem().getDefaultInstance())
            .displayItems((pParameters, pOutput)->{
                ModItems.getEntries().forEach(itemRegistryObject -> {
                    Item item = itemRegistryObject.get();
                    if (item instanceof CreativeItem creativeItem) {
                        creativeItem.fill(pOutput::accept);
                        return;
                    }
                    pOutput.accept(item);
                });
            })
            .build());
    public static void register(IEventBus bus) {
        CREATIVE_TABS.register(bus);
    }

}
