package com.r3944realms.leashedplayer.content.blocks;

import com.r3944realms.leashedplayer.LeashedPlayer;
import com.r3944realms.leashedplayer.content.blocks.type.ItemMemoryBlock;
import com.r3944realms.leashedplayer.content.items.ModItemRegister;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.function.Supplier;

public class ModBlocksRegister {
    public static DeferredRegister<Block> BLOCKS = DeferredRegister.createBlocks(LeashedPlayer.MOD_ID);
    public static DeferredHolder<Block, Block> TEST_BLOCK = register("test_block",
            () -> new ItemMemoryBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.GLASS)
                    .setId(ModBlockResourceKeys.TEST_BLOCK.getResourceKey()))
    );
    public static <T extends Block> DeferredHolder<Item, BlockItem> registerBlockItem(String name , DeferredHolder<T, ? extends T> block, ResourceKey<Item> itemResourceKey){
        return ModItemRegister.registerBlockItem(
                name,
                () -> new BlockItem(block.get(),new Item.Properties().setId(itemResourceKey))
        );
    }
    private static DeferredHolder<Block, Block> register(String name, Supplier<Block> blockSupplier) {
        return BLOCKS.register(name, blockSupplier);
    }
    public static void register(IEventBus eventBus) {
        BLOCKS.register(eventBus);
    }
}
