package net.minecraft.item;

import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class ItemChorusFruit extends ItemFood {
    public ItemChorusFruit(int amount, float saturation) {
        super(amount, saturation, false);
    }

    @Nullable

    /**
     * Called when the player finishes using this Item (E.g. finishes eating.). Not
     * called when the player stops using
     * the Item before the action is complete.
     */
    public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer entityLiving) {
        // TODO: Sound and cooldown
        ItemStack itemstack = super.onItemUseFinish(stack, worldIn, entityLiving);

        if (!worldIn.isRemote) {
            double d0 = entityLiving.posX;
            double d1 = entityLiving.posY;
            double d2 = entityLiving.posZ;

            for (int i = 0; i < 16; ++i) {
                double d3 = entityLiving.posX + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;
                double d4 = MathHelper.clamp_double(
                        entityLiving.posY + (double) (entityLiving.getRNG().nextInt(16) - 8), 0.0D,
                        (double) (worldIn.getActualHeight() - 1));
                double d5 = entityLiving.posZ + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D;

                entityLiving.setPosition(d3, d4, d5);

                if (entityLiving.attemptTeleport(d3, d4, d5)) {
                    // worldIn.playSound((EntityPlayer) null, d0, d1, d2,
                    // SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT,
                    // SoundCategory.PLAYERS, 1.0F, 1.0F);
                    // entityLiving.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
                    break;
                }
            }
            // if (entityLiving instanceof EntityPlayer) {
            // ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 20);
            // }
        }

        return itemstack;
    }
}
