package net.minecraft.world.item;

import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

public class FishingRodItem extends Item implements Vanishable {
    public FishingRodItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bqb, final Player bec, final InteractionHand anf) {
        final ItemStack bki5 = bec.getItemInHand(anf);
        if (bec.fishing != null) {
            if (!bqb.isClientSide) {
                final int integer6 = bec.fishing.retrieve(bki5);
                bki5.<Player>hurtAndBreak(integer6, bec, bec -> bec.broadcastBreakEvent(anf));
            }
            bqb.playSound(null, bec.getX(), bec.getY(), bec.getZ(), SoundEvents.FISHING_BOBBER_RETRIEVE, SoundSource.NEUTRAL, 1.0f, 0.4f / (FishingRodItem.random.nextFloat() * 0.4f + 0.8f));
        }
        else {
            bqb.playSound(null, bec.getX(), bec.getY(), bec.getZ(), SoundEvents.FISHING_BOBBER_THROW, SoundSource.NEUTRAL, 0.5f, 0.4f / (FishingRodItem.random.nextFloat() * 0.4f + 0.8f));
            if (!bqb.isClientSide) {
                final int integer6 = EnchantmentHelper.getFishingSpeedBonus(bki5);
                final int integer7 = EnchantmentHelper.getFishingLuckBonus(bki5);
                bqb.addFreshEntity(new FishingHook(bec, bqb, integer7, integer6));
            }
            bec.awardStat(Stats.ITEM_USED.get(this));
        }
        return InteractionResultHolder.<ItemStack>sidedSuccess(bki5, bqb.isClientSide());
    }
    
    @Override
    public int getEnchantmentValue() {
        return 1;
    }
}
