package net.minecraft.world.item;

import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.entity.animal.Pig;
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 CarrotOnAStickItem extends Item {
    public CarrotOnAStickItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bjw, final Player ayj, final InteractionHand ajk) {
        final ItemStack ben5 = ayj.getItemInHand(ajk);
        if (bjw.isClientSide) {
            return InteractionResultHolder.<ItemStack>pass(ben5);
        }
        if (ayj.isPassenger() && ayj.getVehicle() instanceof Pig) {
            final Pig atq6 = (Pig)ayj.getVehicle();
            if (ben5.getMaxDamage() - ben5.getDamageValue() >= 7 && atq6.boost()) {
                ben5.<Player>hurtAndBreak(7, ayj, ayj -> ayj.broadcastBreakEvent(ajk));
                if (ben5.isEmpty()) {
                    final ItemStack ben6 = new ItemStack(Items.FISHING_ROD);
                    ben6.setTag(ben5.getTag());
                    return InteractionResultHolder.<ItemStack>success(ben6);
                }
                return InteractionResultHolder.<ItemStack>success(ben5);
            }
        }
        ayj.awardStat(Stats.ITEM_USED.get(this));
        return InteractionResultHolder.<ItemStack>pass(ben5);
    }
}
