package com.acethewildfire.acesbs.datagen;

import com.acethewildfire.acesbs.block.FireOakBlocks;
import com.acethewildfire.acesbs.block.LemonWoodBlocks;
import com.acethewildfire.acesbs.block.ModBlocks;
import com.acethewildfire.acesbs.block.custom.EvilBlock;
import com.acethewildfire.acesbs.block.custom.TobaccoCrop;
import com.acethewildfire.acesbs.component.ModDataComponentTypes;
import com.acethewildfire.acesbs.item.*;
import net.fabricmc.fabric.api.client.datagen.v1.provider.FabricModelProvider;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.minecraft.client.data.*;
import net.minecraft.client.item.ItemAsset;
import net.minecraft.client.render.item.model.ConditionItemModel;
import net.minecraft.client.render.item.model.ItemModel;
import net.minecraft.client.render.item.property.bool.HasComponentProperty;
import net.minecraft.client.render.model.json.ModelVariant;
import net.minecraft.client.render.model.json.WeightedVariant;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.Pool;

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.STABLE_ENDTROPY_BLOCK);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.RAW_ENDTROPY_BLOCK);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.PRISMA_STEEL_BLOCK);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.ASHEN_STEEL_BLOCK);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.FRACTAL_DIAMOND_BLOCK);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.HELLFIRE_DIAMOND_BLOCK);
        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.INFERNAL_ASHES_BLOCK);

//        blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.CRYSTAL_ENTROPY);
        blockStateModelGenerator.registerGlassAndPane(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(LemonWoodBlocks.LEMONWOOD_PLANKS);

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

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

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

        blockStateModelGenerator.createLogTexturePool(LemonWoodBlocks.LEMONWOOD_LOG).log(LemonWoodBlocks.LEMONWOOD_LOG).wood(LemonWoodBlocks.LEMONWOOD_WOOD);
        blockStateModelGenerator.createLogTexturePool(LemonWoodBlocks.STRIPPED_LEMONWOOD_LOG).log(LemonWoodBlocks.STRIPPED_LEMONWOOD_LOG).wood(LemonWoodBlocks.STRIPPED_LEMONWOOD_WOOD);

        blockStateModelGenerator.registerSingleton(LemonWoodBlocks.LEMONWOOD_LEAVES, TexturedModel.LEAVES);
//        blockStateModelGenerator.registerFlowerPotPlant(LemonWoodBlocks.LEMONWOOD_SAPLING, LemonWoodBlocks.POTTED_LEMONWOOD_SAPLING, BlockStateModelGenerator.CrossType.NOT_TINTED);

        blockStateModelGenerator.registerDoor(LemonWoodBlocks.LEMONWOOD_DOOR);
//        blockStateModelGenerator.registerTrapdoor(LemonWoodBlocks.LEMONWOOD_TRAPDOOR);

        BlockStateModelGenerator.BlockTexturePool fireOakPool = blockStateModelGenerator.registerCubeAllModelTexturePool(FireOakBlocks.FIRE_OAK_PLANKS);

        fireOakPool.stairs(FireOakBlocks.FIRE_OAK_STAIRS);
        fireOakPool.slab(FireOakBlocks.FIRE_OAK_SLAB);

        fireOakPool.button(FireOakBlocks.FIRE_OAK_BUTTON);
        fireOakPool.pressurePlate(FireOakBlocks.FIRE_OAK_PRESSURE_PLATE);

        fireOakPool.fence(FireOakBlocks.FIRE_OAK_FENCE);
        fireOakPool.fenceGate(FireOakBlocks.FIRE_OAK_FENCE_GATE);
        fireOakPool.wall(FireOakBlocks.FIRE_OAK_WALL);

        blockStateModelGenerator.createLogTexturePool(FireOakBlocks.FIRE_OAK_LOG).log(FireOakBlocks.FIRE_OAK_LOG).wood(FireOakBlocks.FIRE_OAK_WOOD);
        blockStateModelGenerator.createLogTexturePool(FireOakBlocks.STRIPPED_FIRE_OAK_LOG).log(FireOakBlocks.STRIPPED_FIRE_OAK_LOG).wood(FireOakBlocks.STRIPPED_FIRE_OAK_WOOD);

        blockStateModelGenerator.registerSingleton(FireOakBlocks.FIRE_OAK_LEAVES, TexturedModel.LEAVES);
//        blockStateModelGenerator.registerFlowerPotPlant(FireOakBlocks.FIRE_OAK_SAPLING, FireOakBlocks.POTTED_FIRE_OAK_SAPLING, BlockStateModelGenerator.CrossType.NOT_TINTED);

        blockStateModelGenerator.registerDoor(FireOakBlocks.FIRE_OAK_DOOR);
//        blockStateModelGenerator.registerTrapdoor(FireOakBlocks.FIRE_OAK_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(VariantsBlockModelDefinitionCreator.of(ModBlocks.EVIL_BLOCK)
                .with(BlockStateModelGenerator.createBooleanModelMap(EvilBlock.CLICKED,
                        new WeightedVariant(Pool.<ModelVariant>builder().add(new ModelVariant(lampOnIdentifier)).build()),
                        new WeightedVariant(Pool.<ModelVariant>builder().add(new ModelVariant(lampOffIdentifier)).build()))));

        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.AQUARIUM_GRAVEL, 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.DUST_OF_ORDER, Models.GENERATED);
        itemModelGenerator.register(ModItems.INGOT_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(AshenSteelItems.ASHEN_STEEL, Models.GENERATED);
        itemModelGenerator.register(AshenSteelItems.ASHEN_SMITHING_TEMPLATE, Models.GENERATED);
        itemModelGenerator.register(FractalDiamondItems.FRACTAL_DIAMOND, Models.GENERATED);
        itemModelGenerator.register(HellfireDiamondItems.HELLFIRE_DIAMOND, Models.GENERATED);
        itemModelGenerator.register(ModItems.CRAB_RAVE_MUSIC_DISC, Models.GENERATED);

        itemModelGenerator.register(ModItems.THOT_BEGONE, Models.HANDHELD);
        itemModelGenerator.upload(ModItems.KAUPEN_BOW, Models.BOW);
        itemModelGenerator.registerBow(ModItems.KAUPEN_BOW);

        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((PrismaSteelItems.PRISMA_STEEL_HELMET), ModArmorMaterials.PRISMA_KEY, ItemModelGenerator.HELMET_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((PrismaSteelItems.PRISMA_STEEL_CHESTPLATE), ModArmorMaterials.PRISMA_KEY, ItemModelGenerator.CHESTPLATE_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((PrismaSteelItems.PRISMA_STEEL_LEGGINGS), ModArmorMaterials.PRISMA_KEY, ItemModelGenerator.LEGGINGS_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((PrismaSteelItems.PRISMA_STEEL_BOOTS), ModArmorMaterials.PRISMA_KEY, ItemModelGenerator.BOOTS_TRIM_ID_PREFIX, false);

        itemModelGenerator.register(AshenSteelItems.ASHEN_STEEL_SWORD, Models.HANDHELD);
        itemModelGenerator.register(AshenSteelItems.ASHEN_STEEL_PICKAXE, Models.HANDHELD);
        itemModelGenerator.register(AshenSteelItems.ASHEN_STEEL_HAMMER, Models.HANDHELD);
        itemModelGenerator.register(AshenSteelItems.ASHEN_STEEL_AXE, Models.HANDHELD);
        itemModelGenerator.register(AshenSteelItems.ASHEN_STEEL_SHOVEL, Models.HANDHELD);
        itemModelGenerator.register(AshenSteelItems.ASHEN_STEEL_HOE, Models.HANDHELD);

        itemModelGenerator.registerArmor(( AshenSteelItems.ASHEN_STEEL_HELMET), ModArmorMaterials.ASHEN_KEY, ItemModelGenerator.HELMET_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor(( AshenSteelItems.ASHEN_STEEL_CHESTPLATE), ModArmorMaterials.ASHEN_KEY, ItemModelGenerator.CHESTPLATE_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor(( AshenSteelItems.ASHEN_STEEL_LEGGINGS), ModArmorMaterials.ASHEN_KEY, ItemModelGenerator.LEGGINGS_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor(( AshenSteelItems.ASHEN_STEEL_BOOTS), ModArmorMaterials.ASHEN_KEY, ItemModelGenerator.BOOTS_TRIM_ID_PREFIX, false);

        itemModelGenerator.register(FractalDiamondItems.FRACTAL_DIAMOND_SWORD, Models.HANDHELD);
        itemModelGenerator.register(FractalDiamondItems.FRACTAL_DIAMOND_PICKAXE, Models.HANDHELD);
        itemModelGenerator.register(FractalDiamondItems.FRACTAL_DIAMOND_HAMMER, Models.HANDHELD);
        itemModelGenerator.register(FractalDiamondItems.FRACTAL_DIAMOND_AXE, Models.HANDHELD);
        itemModelGenerator.register(FractalDiamondItems.FRACTAL_DIAMOND_SHOVEL, Models.HANDHELD);
        itemModelGenerator.register(FractalDiamondItems.FRACTAL_DIAMOND_HOE, Models.HANDHELD);

        itemModelGenerator.registerArmor((FractalDiamondItems.FRACTAL_DIAMOND_HELMET), ModArmorMaterials.FRACTAL_KEY, ItemModelGenerator.HELMET_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((FractalDiamondItems.FRACTAL_DIAMOND_CHESTPLATE), ModArmorMaterials.FRACTAL_KEY, ItemModelGenerator.CHESTPLATE_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((FractalDiamondItems.FRACTAL_DIAMOND_LEGGINGS), ModArmorMaterials.FRACTAL_KEY, ItemModelGenerator.LEGGINGS_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((FractalDiamondItems.FRACTAL_DIAMOND_BOOTS), ModArmorMaterials.FRACTAL_KEY, ItemModelGenerator.BOOTS_TRIM_ID_PREFIX, false);

        itemModelGenerator.register(HellfireDiamondItems.HELLFIRE_DIAMOND_SWORD, Models.HANDHELD);
        itemModelGenerator.register(HellfireDiamondItems.HELLFIRE_DIAMOND_PICKAXE, Models.HANDHELD);
        itemModelGenerator.register(HellfireDiamondItems.HELLFIRE_DIAMOND_HAMMER, Models.HANDHELD);
        itemModelGenerator.register(HellfireDiamondItems.HELLFIRE_DIAMOND_AXE, Models.HANDHELD);
        itemModelGenerator.register(HellfireDiamondItems.HELLFIRE_DIAMOND_SHOVEL, Models.HANDHELD);
        itemModelGenerator.register(HellfireDiamondItems.HELLFIRE_DIAMOND_HOE, Models.HANDHELD);

        itemModelGenerator.registerArmor((HellfireDiamondItems.HELLFIRE_DIAMOND_HELMET), ModArmorMaterials.HELLFIRE_KEY, ItemModelGenerator.HELMET_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((HellfireDiamondItems.HELLFIRE_DIAMOND_CHESTPLATE), ModArmorMaterials.HELLFIRE_KEY, ItemModelGenerator.CHESTPLATE_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((HellfireDiamondItems.HELLFIRE_DIAMOND_LEGGINGS), ModArmorMaterials.HELLFIRE_KEY, ItemModelGenerator.LEGGINGS_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor((HellfireDiamondItems.HELLFIRE_DIAMOND_BOOTS), ModArmorMaterials.HELLFIRE_KEY, ItemModelGenerator.BOOTS_TRIM_ID_PREFIX, false);


        itemModelGenerator.registerArmor(( ModItems.BERSERKERS_PAULDRON), ModArmorMaterials.BERSERKERS_KEY, ItemModelGenerator.CHESTPLATE_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor(( ModItems.WILDFIRE_BOOTS), ModArmorMaterials.WILDFIRE_KEY, ItemModelGenerator.BOOTS_TRIM_ID_PREFIX, false);
        itemModelGenerator.registerArmor(( ModItems.SOVS_PLATE_CARRIER), ModArmorMaterials.PLATES_KEY, ItemModelGenerator.CHESTPLATE_TRIM_ID_PREFIX, false);

        itemModelGenerator.register(ModItems.FREN_SPAWN_EGG, Models.GENERATED);

        itemModelGenerator.register(ModItems.VULGAR_BONES_SPAWN_EGG, Models.GENERATED);

        ItemModel.Unbaked unbakedWand = ItemModels.basic(itemModelGenerator.upload(ModItems.WAND, Models.GENERATED));
        ItemModel.Unbaked unbakedUsedWand = ItemModels.basic(itemModelGenerator.registerSubModel(ModItems.WAND, "_used", Models.GENERATED));
        itemModelGenerator.output.accept(ModItems.WAND,
                new ItemAsset(new ConditionItemModel.Unbaked(new HasComponentProperty(ModDataComponentTypes.COORDINATES, false),
                        unbakedUsedWand, unbakedWand),
                        new ItemAsset.Properties(false, false)).model());

//        ItemModel.Unbaked unbakedCigarette = ItemModels.basic(itemModelGenerator.upload(ModItems.CIGARETTE, Models.GENERATED));
//        ItemModel.Unbaked unbakedUsedCigarette = ItemModels.basic(itemModelGenerator.registerSubModel(ModItems.CIGARETTE, "_smoking", Models.GENERATED));
//        itemModelGenerator.output.accept(ModItems.CIGARETTE,
//                new ItemAsset(new ConditionItemModel.Unbaked(new HasComponentProperty(ModDataComponentTypes.SMOKING, false),
//                        unbakedUsedCigarette, unbakedCigarette),
//                        new ItemAsset.Properties(false)).model());
//
//        itemModelGenerator.output.accept(ModItems.CIGARETTE_FUNNY,
//                new ItemAsset(new ConditionItemModel.Unbaked(new HasComponentProperty(ModDataComponentTypes.SMOKING, false),
//                        unbakedUsedCigarette, unbakedCigarette),
//                        new ItemAsset.Properties(false)).model());
//
//        itemModelGenerator.output.accept(ModItems.CIGARETTE_LEMON,
//                new ItemAsset(new ConditionItemModel.Unbaked(new HasComponentProperty(ModDataComponentTypes.SMOKING, false),
//                        unbakedUsedCigarette, unbakedCigarette),
//                        new ItemAsset.Properties(false)).model());
//
//        ItemModel.Unbaked unbakedBubblePipe = ItemModels.basic(itemModelGenerator.upload(ModItems.BUBBLE_PIPE, Models.GENERATED));
//        ItemModel.Unbaked unbakedUsedBubblePipe = ItemModels.basic(itemModelGenerator.registerSubModel(ModItems.BUBBLE_PIPE, "_smoking", Models.GENERATED));
//        itemModelGenerator.output.accept(ModItems.BUBBLE_PIPE,
//                new ItemAsset(new ConditionItemModel.Unbaked(new HasComponentProperty(ModDataComponentTypes.SMOKING, false),
//                        unbakedUsedBubblePipe, unbakedBubblePipe),
//                        new ItemAsset.Properties(false)).model());
//
//        ItemModel.Unbaked unbakedCommandCore = ItemModels.basic(itemModelGenerator.upload(ModItems.COMMAND_CORE, Models.GENERATED));
//        ItemModel.Unbaked unbakedUsedCommandCore = ItemModels.basic(itemModelGenerator.registerSubModel(ModItems.COMMAND_CORE, "_active", Models.GENERATED));
//        itemModelGenerator.output.accept(ModItems.COMMAND_CORE,
//                new ItemAsset(new ConditionItemModel.Unbaked(new HasComponentProperty(ModDataComponentTypes.SMOKING, false),
//                        unbakedUsedCommandCore, unbakedCommandCore),
//                        new ItemAsset.Properties(false)).model());
    }

}
