package com.r3944realms.leashedplayer.client.renderer.item.properties.conditionalRange;

import com.mojang.serialization.MapCodec;
import com.r3944realms.leashedplayer.content.items.type.ILeashRopeArrow;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.item.properties.numeric.UseDuration;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public record BowPull() implements ConditionalRangeItemModelProperty {
    public static final MapCodec<BowPull> MAP_CODEC = MapCodec.unit(new BowPull());
    @Override
    public ConditionalRangeData get(ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, int seed, ItemDisplayContext displayContext) {

        if (entity != null && entity.getUseItem() == stack) {
             return ConditionalRangeData.create(ILeashRopeArrow.isLeashRopeArrow(stack, entity), (float)UseDuration.useDuration(stack, entity));
        }
        else return ConditionalRangeData.create(false, 0.0F);
    }

    @Override
    public MapCodec<? extends ConditionalRangeItemModelProperty> type() {
        return MAP_CODEC;
    }
}
