package net.Chipperfluff.chipi.item;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.UseAction;
import net.minecraft.world.World;

import net.Chipperfluff.chipi.effect.ModEffects;

public class MepMilkItem extends Item {

    public MepMilkItem(Settings settings) {
        super(settings);
    }

    @Override
    public UseAction getUseAction(ItemStack stack) {
        return UseAction.DRINK;
    }

    @Override
    public int getMaxUseTime(ItemStack stack) {
        return 32;
    }

    @Override
    public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {

        if (!world.isClient) {
            int durationSeconds = 5 + world.random.nextInt(6);
            int durationTicks = durationSeconds * 20;

            user.addStatusEffect(
                new StatusEffectInstance(
                    ModEffects.CHIPI_BLESSING,
                    durationTicks,
                    0
                )
            );

        }

        if (user instanceof PlayerEntity player && !player.getAbilities().creativeMode) {
            return new ItemStack(Items.BUCKET);
        }

        return stack;
    }
}
