package com.acethewildfire.acesbs.datagen;

import com.acethewildfire.acesbs.effect.ModEffects;
import com.acethewildfire.acesbs.item.ModItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricAdvancementProvider;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementEntry;
import net.minecraft.advancement.AdvancementFrame;
import net.minecraft.advancement.criterion.EffectsChangedCriterion;
import net.minecraft.advancement.criterion.ImpossibleCriterion;
import net.minecraft.advancement.criterion.InventoryChangedCriterion;
import net.minecraft.advancement.criterion.TickCriterion;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.Items;
import net.minecraft.predicate.entity.EntityEffectPredicate;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

public class ModAdvancementProvider extends FabricAdvancementProvider {


    public ModAdvancementProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
        super(output, registryLookup);
    }

    @Override
    public void generateAdvancement(RegistryWrapper.WrapperLookup wrapperLookup, Consumer<AdvancementEntry> consumer) {
        AdvancementEntry root = Advancement.Builder.create()
                .display(
                        ModItems.STABLE_ENTROPY,
                        Text.literal("Ace's BS"),
                        Text.literal("Advancements for Ace's BS"),
                        Identifier.ofVanilla("gui/advancements/backgrounds/stone"),
                        AdvancementFrame.TASK,
                        false,
                        false,
                        false
                )
                .criterion("tick", TickCriterion.Conditions.createTick())
                .build(consumer, "acesbs/root");

        AdvancementEntry cigarette = Advancement.Builder.create()
                .parent(root)
                .display(
                        ModItems.CIGARETTE,
                        Text.literal("Dulling the Edge"),
                        Text.literal("Smoke a cigarette"),
                        null,
                        AdvancementFrame.TASK,
                        true,
                        true,
                        false
                )
                .criterion(
                        "cigarette",
                        EffectsChangedCriterion.Conditions.create(
                                EntityEffectPredicate.Builder.create()
                                        .addEffect(ModEffects.CIGARETTE)
                        )
                )
                .build(consumer, "acesbs/get_cigarette");

        AdvancementEntry jittery = Advancement.Builder.create()
                .parent(cigarette)
                .display(
                        Items.BEE_NEST,
                        Text.literal("Ants in my Pants!"),
                        Text.literal("Feeling jittery, you could really go for a smoke."),
                        null,
                        AdvancementFrame.TASK,
                        true,
                        true,
                        true
                )
                .criterion(
                        "jittery",
                        EffectsChangedCriterion.Conditions.create(
                                EntityEffectPredicate.Builder.create()
                                        .addEffect(ModEffects.JITTERY)
                        )
                )
                .build(consumer, "acesbs/get_jittery");

        AdvancementEntry withdrawal = Advancement.Builder.create()
                .parent(jittery)
                .display(
                        Items.FLINT_AND_STEEL,
                        Text.literal("Anybody got a light?"),
                        Text.literal("Suffer from nicotine withdrawal"),
                        null,
                        AdvancementFrame.TASK,
                        true,
                        true,
                        true
                )
                .criterion(
                        "withdrawal",
                        EffectsChangedCriterion.Conditions.create(
                                EntityEffectPredicate.Builder.create()
                                        .addEffect(ModEffects.WITHDRAWAL)
                        )
                )
                .build(consumer, "acesbs/get_withdrawal");
    }
}
