package net.minecraft.world.item;

import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.player.Player;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.animal.Fox;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;

public class ChorusFruitItem extends Item {
    public ChorusFruitItem(final Properties a) {
        super(a);
    }
    
    @Override
    public ItemStack finishUsingItem(final ItemStack bki, final Level bqb, final LivingEntity aoy) {
        final ItemStack bki2 = super.finishUsingItem(bki, bqb, aoy);
        if (!bqb.isClientSide) {
            final double double6 = aoy.getX();
            final double double7 = aoy.getY();
            final double double8 = aoy.getZ();
            for (int integer12 = 0; integer12 < 16; ++integer12) {
                final double double9 = aoy.getX() + (aoy.getRandom().nextDouble() - 0.5) * 16.0;
                final double double10 = Mth.clamp(aoy.getY() + (aoy.getRandom().nextInt(16) - 8), 0.0, bqb.getHeight() - 1);
                final double double11 = aoy.getZ() + (aoy.getRandom().nextDouble() - 0.5) * 16.0;
                if (aoy.isPassenger()) {
                    aoy.stopRiding();
                }
                if (aoy.randomTeleport(double9, double10, double11, true)) {
                    final SoundEvent ack19 = (aoy instanceof Fox) ? SoundEvents.FOX_TELEPORT : SoundEvents.CHORUS_FRUIT_TELEPORT;
                    bqb.playSound(null, double6, double7, double8, ack19, SoundSource.PLAYERS, 1.0f, 1.0f);
                    aoy.playSound(ack19, 1.0f, 1.0f);
                    break;
                }
            }
            if (aoy instanceof Player) {
                ((Player)aoy).getCooldowns().addCooldown(this, 20);
            }
        }
        return bki2;
    }
}
