package moe.hazu.tinkeringabnormally.data;

import com.teamabnormals.caverns_and_chasms.core.registry.CCAttributes;
import moe.hazu.tinkeringabnormally.TinkeringAbnormally;
import net.minecraft.data.DataGenerator;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.Rarity;
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;
import slimeknights.mantle.data.predicate.item.ItemPredicate;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.library.data.tinkering.AbstractModifierProvider;
import slimeknights.tconstruct.library.json.RandomLevelingValue;
import slimeknights.tconstruct.library.modifiers.modules.behavior.AttributeModule;
import slimeknights.tconstruct.library.modifiers.modules.build.*;
import slimeknights.tconstruct.library.modifiers.modules.combat.MobEffectModule;
import slimeknights.tconstruct.library.modifiers.util.ModifierLevelDisplay;
import slimeknights.tconstruct.library.tools.SlotType;
import slimeknights.tconstruct.library.tools.item.IModifiable;
import slimeknights.tconstruct.library.tools.stat.ToolStats;

import static slimeknights.tconstruct.common.TinkerTags.Items.ARMOR;

public class ModifierProvider extends AbstractModifierProvider implements IConditionBuilder {
    public ModifierProvider(DataGenerator generator) {
        super(generator);
    }

    @Override
    protected void addModifiers() {
        buildModifier(ModifierIds.spinel)
                .levelDisplay(ModifierLevelDisplay.NO_LEVELS)
                .addModule(new RarityModule(Rarity.UNCOMMON))
                .addModule(StatBoostModule.multiplyBase(ToolStats.DURABILITY).flat(-0.25f))
                .addModule(new ModifierSlotModule(SlotType.UPGRADE, 2))
                // melee harvest
                .addModule(StatBoostModule.multiplyBase(ToolStats.ATTACK_DAMAGE).flat(-0.25f))
                .addModule(StatBoostModule.multiplyBase(ToolStats.MINING_SPEED).flat(-0.25f));
        buildModifier(ModifierIds.necromium)
                .levelDisplay(ModifierLevelDisplay.NO_LEVELS)
                .addModule(ModifierRequirementsModule.builder().modifierKey(moe.hazu.tinkeringabnormally.data.ModifierIds.necromium).requireModifier(TinkerTags.Modifiers.GEMS, 1).displayModifier(slimeknights.tconstruct.tools.data.ModifierIds.diamond, 1).build())
                .addModule(new RarityModule(Rarity.RARE))
                .addModule(new VolatileFlagModule(IModifiable.INDESTRUCTIBLE_ENTITY))
                .addModule(StatBoostModule.multiplyBase(ToolStats.DURABILITY).flat(0.2f))
                // armor
                .addModule(AttributeModule.builder(CCAttributes.WEAKNESS_AURA.get(), AttributeModifier.Operation.ADDITION).uniqueFrom(ModifierIds.necromium).toolItem(ItemPredicate.tag(ARMOR)).flat(0.5f))
                // melee harvest
                .addModule(MobEffectModule.builder(MobEffects.MOVEMENT_SLOWDOWN).level(RandomLevelingValue.flat(2)).time(RandomLevelingValue.flat(100)).build())
                .addModule(SetStatModule.set(ToolStats.HARVEST_TIER).value(TinkeringAbnormally.NECROMIUM));
        buildModifier(ModifierIds.sanguine).addModule(AttributeModule.builder(CCAttributes.LIFESTEAL.get(), AttributeModifier.Operation.MULTIPLY_BASE).uniqueFrom(ModifierIds.sanguine).flat(0.05f));
    }

    @Override
    public String getName() {
        return "Tinkering Abnormally Modifiers";
    }
}
