package net.minecraft.world.item;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.fishing.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.level.Level;
import net.minecraft.world.entity.player.Player;
import net.minecraft.resources.ResourceLocation;

public class FishingRodItem extends Item {
    public FishingRodItem(final Properties a) {
        super(a);
        boolean boolean4;
        boolean boolean5;
        this.addProperty(new ResourceLocation("cast"), (ben, bjw, akz) -> {
            if (akz == null) {
                return 0.0f;
            }
            else {
                boolean4 = (akz.getMainHandItem() == ben);
                boolean5 = (akz.getOffhandItem() == ben);
                if (akz.getMainHandItem().getItem() instanceof FishingRodItem) {
                    boolean5 = false;
                }
                return ((boolean4 || boolean5) && akz instanceof Player && akz.fishing != null) ? 1.0f : 0.0f;
            }
        });
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bjw, final Player ayj, final InteractionHand ajk) {
        final ItemStack ben5 = ayj.getItemInHand(ajk);
        if (ayj.fishing != null) {
            if (!bjw.isClientSide) {
                final int integer6 = ayj.fishing.retrieve(ben5);
                ben5.<Player>hurtAndBreak(integer6, ayj, ayj -> ayj.broadcastBreakEvent(ajk));
            }
            bjw.playSound(null, ayj.getX(), ayj.getY(), ayj.getZ(), SoundEvents.FISHING_BOBBER_RETRIEVE, SoundSource.NEUTRAL, 1.0f, 0.4f / (FishingRodItem.random.nextFloat() * 0.4f + 0.8f));
        }
        else {
            bjw.playSound(null, ayj.getX(), ayj.getY(), ayj.getZ(), SoundEvents.FISHING_BOBBER_THROW, SoundSource.NEUTRAL, 0.5f, 0.4f / (FishingRodItem.random.nextFloat() * 0.4f + 0.8f));
            if (!bjw.isClientSide) {
                final int integer6 = EnchantmentHelper.getFishingSpeedBonus(ben5);
                final int integer7 = EnchantmentHelper.getFishingLuckBonus(ben5);
                bjw.addFreshEntity(new FishingHook(ayj, bjw, integer7, integer6));
            }
            ayj.awardStat(Stats.ITEM_USED.get(this));
        }
        return InteractionResultHolder.<ItemStack>success(ben5);
    }
    
    @Override
    public int getEnchantmentValue() {
        return 1;
    }
}
