package studio.halbear.hem_custom.registry.blocks;

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;
import studio.halbear.hem.HemMod;
import studio.halbear.hem.itemgroup.BlueleafTabItemGroup;
import studio.halbear.hem_custom.registry.items.ModItems;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

@ObjectHolder("hem")
@Mod.EventBusSubscriber(modid = "hem", bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModBlocks {
    //public static final DeferredRegister<Block> HEMBLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "hem");
    /*public static final List<Block> HEMBLOCKS = new ArrayList<Block>(){

    };


    @SubscribeEvent
    public static void registerBlocks(final RegistryEvent.Register<Block> event) {
        HEMBLOCKS.add(new Block(AbstractBlock.Properties
                .create(Material.IRON)
                .sound(SoundType.METAL)
                .hardnessAndResistance(2.0f, 1.0f)
                .harvestTool(ToolType.PICKAXE)
        ).setRegistryName("test_block"));
        //IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
        //HEMBLOCKS.register(bus);
        HEMBLOCKS.forEach(block->event.getRegistry().register(block));
    }

    @SubscribeEvent
    public static void registerBlockItems(final RegistryEvent.Register<Item> event) {
        // Ensure the block is not null before creating its item counterpart
        HEMBLOCKS.forEach(block-> {
            if(block != null) {
                BlockItem newBlockItem = new BlockItem(block, new Item.Properties().group(BlueleafTabItemGroup.tab));
                newBlockItem.setRegistryName(block.getRegistryName());
                event.getRegistry().register(newBlockItem);
            }
        });
    }*/

    //private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block){
       // RegistryObject<T> toReturn = ModBlocks.HEMBLOCKS.register(name, block);
       // registerBlockItem(name, toReturn);
       // return toReturn;
   // }

   // private static <T extends Block> void registerBlockItem(String name, RegistryObject<T> block) {
       // ModItems.ITEMS.register(name, () -> new BlockItem(block.get(),
       //         new Item.Properties().group(BlueleafTabItemGroup.tab)));
   // }
}
