package net.minecraft.world.item;

import net.minecraft.world.entity.player.Player;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
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 ben, final Level bjw, final LivingEntity akz) {
        final ItemStack ben2 = super.finishUsingItem(ben, bjw, akz);
        if (!bjw.isClientSide) {
            final double double6 = akz.getX();
            final double double7 = akz.getY();
            final double double8 = akz.getZ();
            for (int integer12 = 0; integer12 < 16; ++integer12) {
                final double double9 = akz.getX() + (akz.getRandom().nextDouble() - 0.5) * 16.0;
                final double double10 = Mth.clamp(akz.getY() + (akz.getRandom().nextInt(16) - 8), 0.0, bjw.getHeight() - 1);
                final double double11 = akz.getZ() + (akz.getRandom().nextDouble() - 0.5) * 16.0;
                if (akz.isPassenger()) {
                    akz.stopRiding();
                }
                if (akz.randomTeleport(double9, double10, double11, true)) {
                    bjw.playSound(null, double6, double7, double8, SoundEvents.CHORUS_FRUIT_TELEPORT, SoundSource.PLAYERS, 1.0f, 1.0f);
                    akz.playSound(SoundEvents.CHORUS_FRUIT_TELEPORT, 1.0f, 1.0f);
                    break;
                }
            }
            if (akz instanceof Player) {
                ((Player)akz).getCooldowns().addCooldown(this, 20);
            }
        }
        return ben2;
    }
}
