package com.acethewildfire.acesbs.datagen;

import com.acethewildfire.acesbs.block.ModBlocks;
import com.acethewildfire.acesbs.block.custom.EvilBlock;
import com.acethewildfire.acesbs.block.custom.TobaccoCrop;
import com.acethewildfire.acesbs.item.ModItems;
import com.acethewildfire.acesbs.item.PrismaSteelItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider;
import net.minecraft.data.client.*;
import net.minecraft.item.ArmorItem;
import net.minecraft.util.Identifier;

import java.util.Optional;

public class ModModelProvider extends FabricModelProvider {

    public ModModelProvider(FabricDataOutput output) {
        super(output);
    }

    @Override
    public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.ENTROPY_ORE);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.DEEPSLATE_ENTROPY_ORE);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.INFERNAL_ASHES_ORE);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.ENDTROPY_ORE);
//        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.ENTROPY_BLOCK);
//        Has a complex texture, use the default blockbench method.
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.STABLE_ENTROPY_BLOCK);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.PRISMA_STEEL_BLOCK);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.INFERNAL_ASHES_BLOCK);

//        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.CRYSTAL_ENTROPY);
        blockStateModelGenerator.registerGlassPane(ModBlocks.CRYSTAL_ENTROPY, ModBlocks.CRYSTAL_ENTROPY_PANE);

        BlockStateModelGenerator.BlockTexturePool lizardPool = blockStateModelGenerator.registerCubeAllModelTexturePool(ModBlocks.LIZARD_PLANKS);
        lizardPool.button(ModBlocks.LIZARD_BUTTON);

        BlockStateModelGenerator.BlockTexturePool lemonwoodPool = blockStateModelGenerator.registerCubeAllModelTexturePool(ModBlocks.LEMONWOOD_PLANKS);


        lemonwoodPool.stairs(ModBlocks.LEMONWOOD_STAIRS);
        lemonwoodPool.slab(ModBlocks.LEMONWOOD_SLAB);

        lemonwoodPool.button(ModBlocks.LEMONWOOD_BUTTON);
        lemonwoodPool.pressurePlate(ModBlocks.LEMONWOOD_PRESSURE_PLATE);

        lemonwoodPool.fence(ModBlocks.LEMONWOOD_FENCE);
        lemonwoodPool.fenceGate(ModBlocks.LEMONWOOD_FENCE_GATE);
        lemonwoodPool.wall(ModBlocks.LEMONWOOD_WALL);

        blockStateModelGenerator.registerLog(ModBlocks.LEMONWOOD_LOG).log(ModBlocks.LEMONWOOD_LOG).wood(ModBlocks.LEMONWOOD_WOOD);
        blockStateModelGenerator.registerLog(ModBlocks.STRIPPED_LEMONWOOD_LOG).log(ModBlocks.STRIPPED_LEMONWOOD_LOG).wood(ModBlocks.STRIPPED_LEMONWOOD_WOOD);

        blockStateModelGenerator.registerSingleton(ModBlocks.LEMONWOOD_LEAVES, TexturedModel.LEAVES);
//        blockStateModelGenerator.registerTintableCross(ModBlocks.LEMONWOOD_SAPLING, BlockStateModelGenerator.TintType.NOT_TINTED);
        blockStateModelGenerator.registerFlowerPotPlant(ModBlocks.LEMONWOOD_SAPLING, ModBlocks.POTTED_LEMONWOOD_SAPLING, BlockStateModelGenerator.TintType.NOT_TINTED);

        blockStateModelGenerator.registerDoor(ModBlocks.LEMONWOOD_DOOR);
        blockStateModelGenerator.registerTrapdoor(ModBlocks.LEMONWOOD_TRAPDOOR);

        Identifier lampOffIdentifier = TexturedModel.CUBE_ALL.upload(ModBlocks.EVIL_BLOCK, blockStateModelGenerator.modelCollector);
        Identifier lampOnIdentifier = blockStateModelGenerator.createSubModel(ModBlocks.EVIL_BLOCK, "_on", Models.CUBE_ALL, TextureMap::all);
        blockStateModelGenerator.blockStateCollector.accept(VariantsBlockStateSupplier.create(ModBlocks.EVIL_BLOCK)
                .coordinate(BlockStateModelGenerator.createBooleanModelMap(EvilBlock.CLICKED, lampOnIdentifier, lampOffIdentifier)));

        blockStateModelGenerator.registerCrop(ModBlocks.TOBACCO_CROP, TobaccoCrop.AGE, 0,1,2,3,4,5,6);
    }

    @Override
    public void generateItemModels(ItemModelGenerator itemModelGenerator) {
        itemModelGenerator.register(ModItems.COOKED_LEMON, Models.GENERATED);
        itemModelGenerator.register(ModItems.LEMON, Models.GENERATED);
        itemModelGenerator.register(ModItems.INFERNAL_BEEF, Models.GENERATED);
        itemModelGenerator.register(ModItems.BRICKED_UP, Models.GENERATED);
        itemModelGenerator.register(ModItems.TOBACCO, Models.GENERATED);
        itemModelGenerator.register(ModItems.RAW_ENTROPY, Models.GENERATED);
        itemModelGenerator.register(ModItems.STABLE_ENTROPY, Models.GENERATED);
        itemModelGenerator.register(ModItems.RAW_ENDTROPY, Models.GENERATED);
        itemModelGenerator.register(ModItems.STABLE_ENDTROPY, Models.GENERATED);
        itemModelGenerator.register(ModItems.ORACLE_LEMON, Models.GENERATED);
        itemModelGenerator.register(ModItems.GREEN_BRICKS, Models.GENERATED);
        itemModelGenerator.register(ModItems.INFERNAL_ASHES, Models.GENERATED);
        itemModelGenerator.register(ModItems.MOTE_OF_ORDER, Models.GENERATED);
//        itemModelGenerator.register(ModItems.WAND, Models.HANDHELD_ROD);
        itemModelGenerator.register(PrismaSteelItems.PRISMA_STEEL, Models.GENERATED);
        itemModelGenerator.register(PrismaSteelItems.PRISMA_SMITHING_TEMPLATE, Models.GENERATED);
        itemModelGenerator.register(ModItems.CRAB_RAVE_MUSIC_DISC, Models.GENERATED);

        itemModelGenerator.register(PrismaSteelItems.PRISMA_STEEL_SWORD, Models.HANDHELD);
        itemModelGenerator.register(PrismaSteelItems.PRISMA_STEEL_PICKAXE, Models.HANDHELD);
        itemModelGenerator.register(PrismaSteelItems.PRISMA_STEEL_HAMMER, Models.HANDHELD);
        itemModelGenerator.register(PrismaSteelItems.PRISMA_STEEL_AXE, Models.HANDHELD);
        itemModelGenerator.register(PrismaSteelItems.PRISMA_STEEL_SHOVEL, Models.HANDHELD);
        itemModelGenerator.register(PrismaSteelItems.PRISMA_STEEL_HOE, Models.HANDHELD);

        itemModelGenerator.registerArmor((ArmorItem) PrismaSteelItems.PRISMA_STEEL_HELMET);
        itemModelGenerator.registerArmor((ArmorItem) PrismaSteelItems.PRISMA_STEEL_CHESTPLATE);
        itemModelGenerator.registerArmor((ArmorItem) PrismaSteelItems.PRISMA_STEEL_LEGGINGS);
        itemModelGenerator.registerArmor((ArmorItem) PrismaSteelItems.PRISMA_STEEL_BOOTS);

        itemModelGenerator.registerArmor((ArmorItem) ModItems.BERSERKERS_PAULDRON);

        itemModelGenerator.register(ModItems.FREN_SPAWN_EGG,
                new Model(Optional.of(Identifier.of("item/template_spawn_egg")), Optional.empty()));
    }
}
