package su.a71.new_soviet.registration;

import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.MapColor;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.text.Text;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;

import net.minecraft.util.shape.VoxelShapes;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.blocks.*;
import su.a71.new_soviet.entity.TVBlockEntity;

public class NSE_Custom extends NSE_BaseRegistration {
    public static final TVBlock TV = new TVBlock(FabricBlockSettings.create().mapColor(MapColor.TERRACOTTA_YELLOW));
    public static final TVBlock RED_TV = new TVBlock(FabricBlockSettings.create().mapColor(MapColor.TERRACOTTA_RED));
    public static final TVBlock BROWN_TV = new TVBlock(FabricBlockSettings.create().mapColor(MapColor.TERRACOTTA_BROWN));
    public static final BlockEntityType<TVBlockEntity> TV_BLOCK_ENTITY = registerBlockEntity("tv_block_entity", TVBlockEntity::new, TV, RED_TV, BROWN_TV);

    public static final RadioReceiverBlock RADIO_RECEIVER = new RadioReceiverBlock();

    public static final SwitchBlock SWITCH = new SwitchBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).notSolid().pistonBehavior(PistonBehavior.DESTROY).strength(1f, 2f).mapColor(MapColor.TERRACOTTA_WHITE));
    public static final TableLampBlock TABLE_LAMP = new TableLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.WOOD).strength(0.9f, 1.5f).mapColor(MapColor.WHITE));
    public static final TableLampBlock VINTAGE_LAMP = new VintageLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(0.9f, 1.5f).mapColor(MapColor.WHITE));
    public static final LightBulbLampBlock LIGHT_BULB_LAMP = new LightBulbLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.GLASS).strength(0.9f, 1.5f).mapColor(MapColor.WHITE).requiresTool());

    public static final CeilingFanBlock CEILING_FAN = new CeilingFanBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.WHITE));

    public static final SirenBlock SIREN = new SirenBlock();

    public static final LandMineBlock LANDMINE = new LandMineBlock(FabricBlockSettings.create().mapColor(MapColor.LIGHT_GRAY).offset(AbstractBlock.OffsetType.XZ).dynamicBounds());

    public static final CheckerBlock WHITE_CHECKER = new CheckerBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).hardness(0.1f).nonOpaque().mapColor(MapColor.WHITE));
    public static final CheckerBlock BLACK_CHECKER = new CheckerBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).hardness(0.1f).nonOpaque().mapColor(MapColor.BLACK));

    public static final ChessBlock WHITE_BISHOP = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.WHITE).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5,8,5,11,9,11), Block.createCuboidShape(5,10,5,11,16,11), Block.createCuboidShape(7,16,7,9,19,9)));
    public static final ChessBlock WHITE_KING = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.WHITE).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5,13,5,11,16,11), Block.createCuboidShape(5.5,5,5.5,10.5,6,10.5), Block.createCuboidShape(5.5,7,5.5,10.5,8,10.5)));
    public static final ChessBlockKnight WHITE_KNIGHT = new ChessBlockKnight(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.WHITE).nonOpaque());
    public static final ChessBlock WHITE_PAWN = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.WHITE).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5.5,5,5.5,10.5,6,10.5), Block.createCuboidShape(5,8,5,11,14,11)));
    public static final ChessBlock WHITE_QUEEN = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.WHITE).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5,13,5,11,16,11), Block.createCuboidShape(5.5,5,5.5,10.5,6,10.5), Block.createCuboidShape(5.5,7,5.5,10.5,8,10.5)));
    public static final ChessBlock WHITE_ROOK = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.WHITE).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5,10,5,11,15,11), Block.createCuboidShape(5.5,5,5.5,10.5,6,10.5), Block.createCuboidShape(5.5,7,5.5,10.5,8,10.5)));

    public static final ChessBlock BLACK_BISHOP = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.BLACK).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5,8,5,11,9,11), Block.createCuboidShape(5,10,5,11,16,11), Block.createCuboidShape(7,16,7,9,19,9)));
    public static final ChessBlock BLACK_KING = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.BLACK).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5,13,5,11,16,11), Block.createCuboidShape(5.5,5,5.5,10.5,6,10.5), Block.createCuboidShape(5.5,7,5.5,10.5,8,10.5)));
    public static final ChessBlockKnight BLACK_KNIGHT = new ChessBlockKnight(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.BLACK).nonOpaque());
    public static final ChessBlock BLACK_PAWN = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.BLACK).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5.5,5,5.5,10.5,6,10.5), Block.createCuboidShape(5,8,5,11,14,11)));
    public static final ChessBlock BLACK_QUEEN = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.BLACK).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5,13,5,11,16,11), Block.createCuboidShape(5.5,5,5.5,10.5,6,10.5), Block.createCuboidShape(5.5,7,5.5,10.5,8,10.5)));
    public static final ChessBlock BLACK_ROOK = new ChessBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).mapColor(DyeColor.BLACK).nonOpaque(), VoxelShapes.union(Block.createCuboidShape(5,10,5,11,15,11), Block.createCuboidShape(5.5,5,5.5,10.5,6,10.5), Block.createCuboidShape(5.5,7,5.5,10.5,8,10.5)));

    private static final ItemGroup NSE_CUSTOM_TAB = FabricItemGroup.builder()
            .icon(() -> new ItemStack(TV))
            .displayName(Text.translatable("itemGroup.new_soviet.custom"))
            .build();

    public static void init() {
        Registry.register(Registries.ITEM_GROUP, new Identifier(NewSoviet.MOD_ID, "custom"), NSE_CUSTOM_TAB);
        registerBlock("tv", () -> TV, NSE_CUSTOM_TAB);
        registerBlock("red_tv", () -> RED_TV, NSE_CUSTOM_TAB);
        registerBlock("brown_tv", () -> BROWN_TV, NSE_CUSTOM_TAB);
        registerBlock("radio_receiver", () -> RADIO_RECEIVER, NSE_CUSTOM_TAB);
        registerBlock("table_lamp", () -> TABLE_LAMP, NSE_CUSTOM_TAB);
        registerBlock("vintage_lamp", () -> VINTAGE_LAMP, NSE_CUSTOM_TAB);
        registerBlock("light_bulb_lamp", () -> LIGHT_BULB_LAMP, NSE_CUSTOM_TAB);
        registerBlock("ceiling_fan", () -> CEILING_FAN, NSE_CUSTOM_TAB);
        registerBlock("siren", () -> SIREN, NSE_CUSTOM_TAB);
        registerBlock("landmine", () -> LANDMINE, NSE_CUSTOM_TAB);
        registerBlock("switch", () -> SWITCH, NSE_CUSTOM_TAB);
        registerBlock("white_checker", () -> WHITE_CHECKER, NSE_CUSTOM_TAB);
        registerBlock("black_checker", () -> BLACK_CHECKER, NSE_CUSTOM_TAB);
        registerBlock("white_pawn", () -> WHITE_PAWN, NSE_CUSTOM_TAB);
        registerBlock("white_queen", () -> WHITE_QUEEN, NSE_CUSTOM_TAB);
        registerBlock("white_rook", () -> WHITE_ROOK, NSE_CUSTOM_TAB);
        registerBlock("white_knight", () -> WHITE_KNIGHT, NSE_CUSTOM_TAB);
        registerBlock("white_bishop", () -> WHITE_BISHOP, NSE_CUSTOM_TAB);
        registerBlock("white_king", () -> WHITE_KING, NSE_CUSTOM_TAB);
        registerBlock("black_pawn", () -> BLACK_PAWN, NSE_CUSTOM_TAB);
        registerBlock("black_queen", () -> BLACK_QUEEN, NSE_CUSTOM_TAB);
        registerBlock("black_knight", () -> BLACK_KNIGHT, NSE_CUSTOM_TAB);
        registerBlock("black_rook", () -> BLACK_ROOK, NSE_CUSTOM_TAB);
        registerBlock("black_bishop", () -> BLACK_BISHOP, NSE_CUSTOM_TAB);
        registerBlock("black_king", () -> BLACK_KING, NSE_CUSTOM_TAB);
    }
}