package com.acethewildfire.acesbs.item.custom;

import com.acethewildfire.acesbs.sounds.ModSounds;
import com.acethewildfire.acesbs.sounds.PlayerAttachedSound;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.consume.UseAction;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;

public class AquariumGravel extends Item {
    public AquariumGravel(Settings settings) {
        super(settings);
    }

    // Store the currently playing sound (client only)
    private static PlayerAttachedSound activeSound;

    @Override
    public ActionResult use(World world, PlayerEntity user, Hand hand) {
        ItemStack stack = user.getStackInHand(hand);

        user.setCurrentHand(hand);

        return ActionResult.CONSUME;
    }

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

    @Override
    public int getMaxUseTime(ItemStack stack, LivingEntity user) {
        return 32; // basically infinite hold
    }

    @Override
    public void usageTick(World world, LivingEntity user, ItemStack stack, int remainingUseTicks) {
        super.usageTick(world, user, stack, remainingUseTicks);

        if (remainingUseTicks % 10 == 0){
            world.playSound(
                    null,
                    user.getX(),
                    user.getY(),
                    user.getZ(),
                    ModSounds.CRUNCH,
                    SoundCategory.PLAYERS,
                    1.0F,
                    1.0F
            );
        }

    }

    @Override
    public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
        world.playSound(
                null,
                user.getX(),
                user.getY(),
                user.getZ(),
                ModSounds.CRUNCH,
                SoundCategory.PLAYERS,
                1.0F,
                1.0F
        );
        return stack;
    }
}
