package top.r3944realms.lib39.content.item;

import com.mojang.authlib.GameProfile;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.client.renderer.item.DollItemRenderer;
import top.r3944realms.lib39.content.register.Lib39Blocks;
import top.r3944realms.lib39.util.GameProfileHelper;

import java.util.List;
import java.util.function.Consumer;

/**
 * The type Doll item.
 */
public class DollItem extends BlockItem {
    /**
     * Instantiates a new Doll item.
     *
     * @param properties the properties
     */
    public DollItem(Properties properties) {
        super(Lib39Blocks.DOLL.get(), properties);
    }

    @Override
    public void initializeClient(@NotNull Consumer<IClientItemExtensions> consumer) {
        consumer.accept(new IClientItemExtensions() {
            @Override
            public BlockEntityWithoutLevelRenderer getCustomRenderer() {
                return DollItemRenderer.getInstance();
            }
        });
    }

    @Override
    public boolean canEquip(ItemStack stack, EquipmentSlot armorType, Entity entity) {
        return armorType == EquipmentSlot.HEAD;
    }

    @Override
    public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @NotNull List<Component> tooltip, @NotNull TooltipFlag flag) {
        GameProfile profileFromItemStack = GameProfileHelper.getProfileFromItemStack(stack);
        if (profileFromItemStack != null && profileFromItemStack.getName() != null) {
            tooltip.add(Component.translatable("tooltip.lib39.content.doll.hover.1", profileFromItemStack.getName()));
        }
        tooltip.add(Component.translatable("tooltip.lib39.content.doll.hover.2"));
    }
}
