/*
 *
 * BlockManager
 *
 * The mod block manager
 *
 *
*/

package jesse.keeblarcraft.CustomBlocks;

import java.util.HashMap;

import jesse.keeblarcraft.Keeblarcraft;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

public class BlockManager {

    /// The block list. DO NOT ADD TO THE LIST YOURSELF. USE
    /// THE RegisterBlock(...) FUNCTION OTHERWISE YOUR BLOCK WILL
    /// NOT BE REGISTERED PROPERLY AND MAY BREAK THE GAME
    // public static final List<Block> blockList = new ArrayList<Block>();
    public static final HashMap<String, Block> blockList = new HashMap<String, Block>();

    /////////////////////////////////////////////////////////////////////////////
    /// @fn         RegisterBlock
    ///
    /// @arg[in]    name is the block name. IMPORTANT: Name must adhere to rules:
    ///             1. The name provided here must match these names:
    ///                 * This blocks models/block name
    ///                 * This blocks textures/block name
    ///             2 Name must be lowercase & no special characters besides '_'
    ///
    /// @arg[in]    block is the block to be added to the block list
    ///
    /// @brief      This is the call to register your block to the game! Please
    ///             do not forget to update the models/block json file, the
    ///             textures/block png name, and finally the lang/en_us.json file
    /////////////////////////////////////////////////////////////////////////////
    public static void RegisterBlock(String name, Block block) {

        // This call registers the block as an item in inventories
        Registry.register(Registries.ITEM, new Identifier(Keeblarcraft.MOD_ID, name), new BlockItem(block, new FabricItemSettings()));

        // This call registers the block as placed
        Block newBlock = Registry.register(Registries.BLOCK, new Identifier(Keeblarcraft.MOD_ID, name), block);

        // Add the block to the block list
        blockList.put(name, newBlock);
    }

    /////////////////////////////////////////////////////////////////////////////
    /// @fn         GetBlock
    ///
    /// @brief      Gets a block from the block list by name
    ///
    /// @return     Returns a block from the blockList object if name is found,
    ///             will return null if not found
    /////////////////////////////////////////////////////////////////////////////
    public static Block GetBlock(String name) {
        return blockList.get(name);
    }
}
