package com.acethewildfire.acesbs.util;

import com.acethewildfire.acesbs.AcesBS;
import com.acethewildfire.acesbs.component.ModDataComponentTypes;
import com.acethewildfire.acesbs.item.ModItems;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;

public class ModModelPredicates {

    public static void registerModelPredicates () {
        ModelPredicateProviderRegistry.register(ModItems.WAND, Identifier.of(AcesBS.MOD_ID, "used"),
                (stack, world, entity, seed) -> stack.get(ModDataComponentTypes.COORDINATES) != null ? 1f : 0f);

        ModelPredicateProviderRegistry.register(ModItems.CIGARETTE, Identifier.of(AcesBS.MOD_ID, "smoking"),
                (stack, world, entity, seed) -> Boolean.TRUE.equals(stack.get(ModDataComponentTypes.SMOKING)) ? 1f : 0f);

        ModelPredicateProviderRegistry.register(ModItems.CIGARETTE_FUNNY, Identifier.of(AcesBS.MOD_ID, "smoking"),
                (stack, world, entity, seed) -> Boolean.TRUE.equals(stack.get(ModDataComponentTypes.SMOKING)) ? 1f : 0f);

        ModelPredicateProviderRegistry.register(ModItems.CIGARETTE_LEMON, Identifier.of(AcesBS.MOD_ID, "smoking"),
                (stack, world, entity, seed) -> Boolean.TRUE.equals(stack.get(ModDataComponentTypes.SMOKING)) ? 1f : 0f);

        registerCustomBow(ModItems.KAUPEN_BOW);
    }

    private static void registerCustomBow(Item item){
        ModelPredicateProviderRegistry.register(item, Identifier.ofVanilla("pull"), (stack, world, entity, seed) -> {
            if (entity == null) {
                return 0.0F;
            } else {
                return entity.getActiveItem() != stack ? 0.0F : (stack.getMaxUseTime(entity) - entity.getItemUseTimeLeft()) / 20.0F;
            }
        });
        ModelPredicateProviderRegistry.register(
                item,
                Identifier.ofVanilla("pulling"),
                (stack, world, entity, seed) -> entity != null && entity.isUsingItem() && entity.getActiveItem() == stack ? 1.0F : 0.0F
        );
    }
}
