package com.r3944realms.modernlifepatch.datagen.provider;

import com.r3944realms.modernlifepatch.ModernLifePatch;
import com.r3944realms.modernlifepatch.content.blocks.ModBlocks;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.client.model.generators.BlockModelBuilder;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.client.model.generators.ModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.ForgeRegistries;

public class ModBlockStatesProvider extends BlockStateProvider {
    public ModBlockStatesProvider(PackOutput packOutput, ExistingFileHelper existingFileHelper) {
        super(packOutput, ModernLifePatch.MOD_ID, existingFileHelper);
    }

    private ResourceLocation key(Block block) {
        return ForgeRegistries.BLOCKS.getKey(block);
    }

    @Override
    protected void registerStatesAndModels() {
        registerBarrierStates(ModBlocks.LIGHT_GRAY_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/light_gray_concrete_barrier"));
        registerBarrierStates(ModBlocks.WHITE_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/white_concrete_barrier"));
        registerBarrierStates(ModBlocks.ORANGE_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/orange_concrete_barrier"));
        registerBarrierStates(ModBlocks.MAGENTA_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/magenta_concrete_barrier"));
        registerBarrierStates(ModBlocks.LIGHT_BLUE_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/light_blue_concrete_barrier"));
        registerBarrierStates(ModBlocks.YELLOW_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/yellow_concrete_barrier"));
        registerBarrierStates(ModBlocks.LIME_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/lime_concrete_barrier"));
        registerBarrierStates(ModBlocks.PINK_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/pink_concrete_barrier"));
        registerBarrierStates(ModBlocks.GRAY_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/gray_concrete_barrier"));
        registerBarrierStates(ModBlocks.CYAN_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/cyan_concrete_barrier"));
        registerBarrierStates(ModBlocks.PURPLE_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/purple_concrete_barrier"));
        registerBarrierStates(ModBlocks.BLUE_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/blue_concrete_barrier"));
        registerBarrierStates(ModBlocks.BROWN_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/brown_concrete_barrier"));
        registerBarrierStates(ModBlocks.GREEN_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/green_concrete_barrier"));
        registerBarrierStates(ModBlocks.RED_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/red_concrete_barrier"));
        registerBarrierStates(ModBlocks.BLACK_CONCRETE_BARRIER.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "block/black_concrete_barrier"));
        registerNumberStates(ModBlocks.NULL_BLOCK.get(), "null");
        registerNumberStates(ModBlocks.ONE_BLOCK.get(), "one");
        registerNumberStates(ModBlocks.TWO_BLOCK.get(), "two");
        registerNumberStates(ModBlocks.THREE_BLOCK.get(), "three");
        registerNumberStates(ModBlocks.FOUR_BLOCK.get(), "four");
        registerNumberStates(ModBlocks.FIVE_BLOCK.get(), "five");
        registerNumberStates(ModBlocks.SIX_BLOCK.get(), "six");
        registerNumberStates(ModBlocks.SEVEN_BLOCK.get(), "seven");
        registerNumberStates(ModBlocks.EIGHT_BLOCK.get(), "eight");
        registerNumberStates(ModBlocks.NINE_BLOCK.get(), "nine");
        registerNumberStates(ModBlocks.ZERO_BLOCK.get(), "zero");
    }
    public void registerNumberStates(Block block, String number) {
        BlockModelBuilder numberBlock = models().cubeAll(number + "_block", new ResourceLocation(ModernLifePatch.MOD_ID, "block/" + number + "_block"));
        horizontalBlock(block, numberBlock);
        simpleBlockItem(block, numberBlock);
    }
    public void registerBarrierStates(Block block, ResourceLocation location) {
        ModelFile.ExistingModelFile existingFile = models().getExistingFile(location);
        horizontalBlock(block, existingFile, 0);
        simpleBlockItem(block, existingFile);
    }

    public String name(Block block) {
        return key(block).getPath();
    }
}
