package net.yyc12345.teyvatcraft.init;

import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricMaterialBuilder;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.Block;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.OreBlock;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import net.yyc12345.teyvatcraft.blocks.*;

public class BlocksManager {

    // ==================== ore
    public static final Block MAGICAL_CRYSTAL_CHUNK_ORE =  new OreBlock(getOreBlockSettings(4, 4.0f));
    public static final Block CRYSTAL_CHUNK_ORE = new OreBlock(getOreBlockSettings(3, 4.0f));
    public static final Block WHITE_IRON_CHUNK_ORE  = new OreBlock(getOreBlockSettings(2, 3.0f));
    public static final Block IRON_CHUNK_ORE = new OreBlock(getOreBlockSettings(1, 3.0f));
    public static final Block STARSILVER_ORE = new OreBlock(getOreBlockSettings(1, 2.0f));
    public static final Block NOCTILUCOUS_JADE_ORE = new OreBlock(getOreBlockSettings(1, 3.0f));
    public static final Block COR_LAPIS_ORE = new OreBlock(getOreBlockSettings(1, 3.0f));

    // ==================== crops
    public static final Block RICE = new TeyvatCropBlock();
    public static final Block TOMATO = new TeyvatCropBlock();
    public static final Block ONION = new TeyvatCropBlock();
    public static final Block CABBAGE = new TeyvatCropBlock();
    public static final Block RADISH = new TeyvatCropBlock();

    // flower & sweet berry bush like plant
    public static final Block CALLA_LILY = new TeyvatFlowerLikePlantBlock();
    public static final Block DANDELION_SEED = new TeyvatFlowerLikePlantBlock();
    public static final Block JUEYUN_CHILI = new TeyvatSweetBerryBushLikePlantBlock();
    public static final Block SMALL_LAMP_GRASS = new TeyvatFlowerLikePlantBlock();
    public static final Block MINT = new TeyvatFlowerLikePlantBlock();
    public static final Block SWEET_FLOWER = new TeyvatFlowerLikePlantBlock();
    public static final Block BERRY = new TeyvatSweetBerryBushLikePlantBlock();
    public static final Block SNAPDRAGON = new TeyvatFlowerLikePlantBlock();
    public static final Block MATSUTAKE = new TeyvatFlowerLikePlantBlock();
    public static final Block HORSETAIL = new TeyvatFlowerLikePlantBlock();
    public static final Block CECILIA = new TeyvatFlowerLikePlantBlock();
    public static final Block GLAZE_LILY = new TeyvatFlowerLikePlantBlock();
    public static final Block PHILANEMO_MUSHROOM = new TeyvatFlowerLikePlantBlock();
    public static final Block SILK_FLOWER = new TeyvatSweetBerryBushLikePlantBlock();
    public static final Block VALBERRY = new TeyvatSweetBerryBushLikePlantBlock();
    public static final Block WINDWHEEL_ASTER = new TeyvatFlowerLikePlantBlock();
    public static final Block WOLFHOOK = new TeyvatSweetBerryBushLikePlantBlock();
    public static final Block QINGXIN = new TeyvatFlowerLikePlantBlock();

    
    private static FabricBlockSettings getOreBlockSettings(int pickaxeLevel, float strength) {
        return FabricBlockSettings.of(new FabricMaterialBuilder(MaterialColor.STONE).build()).breakByTool(FabricToolTags.PICKAXES, pickaxeLevel).requiresTool().strength(strength, strength);
    }

    private static void registerCrop(Block bl, Item blItem, String name) {
        ((TeyvatCropBlock)bl).setSeedsItem(blItem);   // set seeds
        BlockRenderLayerMap.INSTANCE.putBlock(bl, RenderLayer.getCutoutMipped());   // set transparent display mode
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", name), bl); //register block self
    }

    private static void registerTeyvatFlowerLikePlant(Block bl, String name) {
        BlockRenderLayerMap.INSTANCE.putBlock(bl, RenderLayer.getCutoutMipped());   // set transparent display mode
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", name), bl);
    }
    private static void registerTeyvatSweetBerryBushLikePlant(Block bl, String name, Item droppedItem) {
        BlockRenderLayerMap.INSTANCE.putBlock(bl, RenderLayer.getCutoutMipped());   // set transparent display mode
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", name), bl);
        ((TeyvatSweetBerryBushLikePlantBlock)bl).setDroppedItem(droppedItem);
    }

    public static void RegisterAll() {
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "magical_crystal_chunk_ore"), MAGICAL_CRYSTAL_CHUNK_ORE);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "crystal_chunk_ore"), CRYSTAL_CHUNK_ORE);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "white_iron_chunk_ore"), WHITE_IRON_CHUNK_ORE);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "iron_chunk_ore"), IRON_CHUNK_ORE);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "starsilver_ore"), STARSILVER_ORE);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "noctilucous_jade_ore"), NOCTILUCOUS_JADE_ORE);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "cor_lapis_ore"), COR_LAPIS_ORE);

        // crops
        registerCrop(RICE, ItemsManager.RICE_SEED, "rice");
        registerCrop(TOMATO, ItemsManager.TOMATO, "tomato");
        registerCrop(ONION, ItemsManager.ONION, "onion");
        registerCrop(CABBAGE, ItemsManager.CABBAGE, "cabbage");
        registerCrop(RADISH, ItemsManager.RADISH, "radish");

        // flower & sweet berry bush like plant
        registerTeyvatFlowerLikePlant(CALLA_LILY, "calla_lily");
        registerTeyvatFlowerLikePlant(DANDELION_SEED, "dandelion_seed");
        registerTeyvatSweetBerryBushLikePlant(JUEYUN_CHILI, "jueyun_chili", ItemsManager.JUEYUN_CHILI);
        registerTeyvatFlowerLikePlant(SMALL_LAMP_GRASS, "small_lamp_grass");
        registerTeyvatFlowerLikePlant(MINT, "mint");
        registerTeyvatFlowerLikePlant(SWEET_FLOWER, "sweet_flower");
        registerTeyvatSweetBerryBushLikePlant(BERRY, "berry", ItemsManager.BERRY);
        registerTeyvatFlowerLikePlant(SNAPDRAGON, "snapdragon");
        registerTeyvatFlowerLikePlant(MATSUTAKE, "matsutake");
        registerTeyvatFlowerLikePlant(HORSETAIL, "horsetail");
        registerTeyvatFlowerLikePlant(CECILIA, "cecilia");
        registerTeyvatFlowerLikePlant(GLAZE_LILY, "glaze_lily");
        registerTeyvatFlowerLikePlant(PHILANEMO_MUSHROOM, "philanemo_mushroom");
        registerTeyvatSweetBerryBushLikePlant(SILK_FLOWER, "silk_flower", ItemsManager.SILK_FLOWER);
        registerTeyvatSweetBerryBushLikePlant(VALBERRY, "valberry", ItemsManager.VALBERRY);
        registerTeyvatFlowerLikePlant(WINDWHEEL_ASTER, "windwheel_aster");
        registerTeyvatSweetBerryBushLikePlant(WOLFHOOK, "wolfhook", ItemsManager.WOLFHOOK);
        registerTeyvatFlowerLikePlant(QINGXIN, "qingxin");
        

    }
}
