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.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.OreBlock;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.yyc12345.teyvatcraft.blocks.TeyvatCropBlock;

public class BlocksManager {

    // ==================== ore
    public static final Block MAGICAL_CRYSTAL_CHUNK_ORE =  new OreBlock(FabricBlockSettings.of(new FabricMaterialBuilder(MaterialColor.STONE).build()).breakByTool(FabricToolTags.PICKAXES, 4).requiresTool().strength(4.0F, 4.0F));
    public static final Block CRYSTAL_CHUNK_ORE = new OreBlock(FabricBlockSettings.of(new FabricMaterialBuilder(MaterialColor.STONE).build()).breakByTool(FabricToolTags.PICKAXES, 3).requiresTool().strength(4.0F, 4.0F));
    public static final Block WHITE_IRON_CHUNK_ORE  = new OreBlock(FabricBlockSettings.of(new FabricMaterialBuilder(MaterialColor.STONE).build()).breakByTool(FabricToolTags.PICKAXES, 2).requiresTool().strength(3.0F, 3.0F));
    public static final Block IRON_CHUNK_ORE = new OreBlock(FabricBlockSettings.of(new FabricMaterialBuilder(MaterialColor.STONE).build()).breakByTool(FabricToolTags.PICKAXES, 1).requiresTool().strength(3.0F, 3.0F));
    public static final Block STARSILVER_ORE = new OreBlock(FabricBlockSettings.of(new FabricMaterialBuilder(MaterialColor.STONE).build()).breakByTool(FabricToolTags.PICKAXES, 1).requiresTool().strength(2.0F, 2.0F));

    // ==================== crops
    public static final Block RICE = new TeyvatCropBlock(FabricBlockSettings.of(Material.PLANT).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP).nonOpaque());
    public static final Block TOMATO = new TeyvatCropBlock(FabricBlockSettings.of(Material.PLANT).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP));
    public static final Block ONION = new TeyvatCropBlock(FabricBlockSettings.of(Material.PLANT).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP));
    public static final Block CABBAGE = new TeyvatCropBlock(FabricBlockSettings.of(Material.PLANT).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP));
    public static final Block RADISH = new TeyvatCropBlock(FabricBlockSettings.of(Material.PLANT).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP));
    

    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);

        // crops
        ((TeyvatCropBlock)RICE).setSeedsItem(ItemsManager.RICE_SEED);
        ((TeyvatCropBlock)TOMATO).setSeedsItem(ItemsManager.TOMATO);
        ((TeyvatCropBlock)ONION).setSeedsItem(ItemsManager.ONION);
        ((TeyvatCropBlock)CABBAGE).setSeedsItem(ItemsManager.CABBAGE);
        ((TeyvatCropBlock)RADISH).setSeedsItem(ItemsManager.RADISH);
        
        BlockRenderLayerMap.INSTANCE.putBlock(RICE, RenderLayer.getCutoutMipped());
        BlockRenderLayerMap.INSTANCE.putBlock(TOMATO, RenderLayer.getCutoutMipped());
        BlockRenderLayerMap.INSTANCE.putBlock(ONION, RenderLayer.getCutoutMipped());
        BlockRenderLayerMap.INSTANCE.putBlock(CABBAGE, RenderLayer.getCutoutMipped());
        BlockRenderLayerMap.INSTANCE.putBlock(RADISH, RenderLayer.getCutoutMipped());

        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "rice"), RICE);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "tomato"), TOMATO);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "onion"), ONION);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "cabbage"), CABBAGE);
        Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "radish"), RADISH);
    }
}
