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.LivingEntity;
import net.minecraft.world.entity.projectile.Snowball;
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 SnowballItem extends Item {
    public SnowballItem(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);
        bjw.playSound(null, ayj.getX(), ayj.getY(), ayj.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5f, 0.4f / (SnowballItem.random.nextFloat() * 0.4f + 0.8f));
        if (!bjw.isClientSide) {
            final Snowball azc6 = new Snowball(bjw, ayj);
            azc6.setItem(ben5);
            azc6.shootFromRotation(ayj, ayj.xRot, ayj.yRot, 0.0f, 1.5f, 1.0f);
            bjw.addFreshEntity(azc6);
        }
        ayj.awardStat(Stats.ITEM_USED.get(this));
        if (!ayj.abilities.instabuild) {
            ben5.shrink(1);
        }
        return InteractionResultHolder.<ItemStack>success(ben5);
    }
}
