package com.r3944realms.leashedplayer.content.items.type;

import com.r3944realms.leashedplayer.content.items.ModItemRegister;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.BowItem;
import net.minecraft.world.item.CrossbowItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ChargedProjectiles;

public interface ILeashRopeArrow {
    static boolean isLeashRopeArrow(ItemStack bowStack, LivingEntity entity) {
        Item item = bowStack.getItem();
        if(item instanceof BowItem) {
            if (entity == null) return false;
            ItemStack projectile = entity.getProjectile(bowStack);
            return projectile.getItem() instanceof ILeashRopeArrow;
            
        } else if (item instanceof CrossbowItem) {
            ChargedProjectiles chargedProjectiles = bowStack.get(DataComponents.CHARGED_PROJECTILES);
            return chargedProjectiles != null &&
                    (chargedProjectiles.contains(ModItemRegister.LEASH_ROPE_ARROW.get()) ||
                    chargedProjectiles.contains(ModItemRegister.SPECTRAL_LEASH_ROPE_ARROW.get()) ||
                    chargedProjectiles.contains(ModItemRegister.TIPPED_LEASH_ROPE_ARROW.get()));
        }
//        if (entity instanceof Player player) {
//            if (bowStack.getItem() instanceof CrossbowItem) {}
//            // 获取将要发射的弹药
//            ItemStack projectileStack = player.getProjectile(bowStack);
//
//            // 判断该弹药是否为拴绳箭
//            return projectileStack.getItem() instanceof ILeashRopeArrow;
//        } else if (entity == null) {
//            if (bowStack.getItem() instanceof CrossbowItem ) {
//                ChargedProjectiles chargedProjectiles = bowStack.get(DataComponents.CHARGED_PROJECTILES);
//                if (chargedProjectiles == null || chargedProjectiles.isEmpty()) {
//                    return false;
//                }
//                return chargedProjectiles.contains(ModItemRegister.LEASH_ROPE_ARROW.get()) ||
//                        chargedProjectiles.contains(ModItemRegister.SPECTRAL_LEASH_ROPE_ARROW.get()) ||
//                        chargedProjectiles.contains(ModItemRegister.TIPPED_LEASH_ROPE_ARROW.get());
//            }
//        }
        return false;
    }
}
