001package net.minecraft.entity.item;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.entity.EntityLiving;
006import net.minecraft.entity.player.EntityPlayerMP;
007import net.minecraft.entity.projectile.EntityThrowable;
008import net.minecraft.util.DamageSource;
009import net.minecraft.util.MovingObjectPosition;
010import net.minecraft.world.World;
011import net.minecraftforge.common.MinecraftForge;
012import net.minecraftforge.event.entity.living.EnderTeleportEvent;
013
014public class EntityEnderPearl extends EntityThrowable
015{
016    public EntityEnderPearl(World par1World)
017    {
018        super(par1World);
019    }
020
021    public EntityEnderPearl(World par1World, EntityLiving par2EntityLiving)
022    {
023        super(par1World, par2EntityLiving);
024    }
025
026    @SideOnly(Side.CLIENT)
027    public EntityEnderPearl(World par1World, double par2, double par4, double par6)
028    {
029        super(par1World, par2, par4, par6);
030    }
031
032    /**
033     * Called when this EntityThrowable hits a block or entity.
034     */
035    protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
036    {
037        if (par1MovingObjectPosition.entityHit != null)
038        {
039            par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
040        }
041
042        for (int i = 0; i < 32; ++i)
043        {
044            this.worldObj.spawnParticle("portal", this.posX, this.posY + this.rand.nextDouble() * 2.0D, this.posZ, this.rand.nextGaussian(), 0.0D, this.rand.nextGaussian());
045        }
046
047        if (!this.worldObj.isRemote)
048        {
049            if (this.getThrower() != null && this.getThrower() instanceof EntityPlayerMP)
050            {
051                EntityPlayerMP entityplayermp = (EntityPlayerMP)this.getThrower();
052
053                if (!entityplayermp.playerNetServerHandler.connectionClosed && entityplayermp.worldObj == this.worldObj)
054                {
055                    EnderTeleportEvent event = new EnderTeleportEvent(entityplayermp, this.posX, this.posY, this.posZ, 5);
056                    if (!MinecraftForge.EVENT_BUS.post(event)){
057                        this.getThrower().setPositionAndUpdate(event.targetX, event.targetY, event.targetZ);
058                        this.getThrower().fallDistance = 0.0F;
059                        this.getThrower().attackEntityFrom(DamageSource.fall, event.attackDamage);
060                    }
061
062                }
063            }
064
065            this.setDead();
066        }
067    }
068}