package net.minecraft.entity.projectile;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;

public class EntityWitherSkull extends EntityFireball
{
	private static final String __OBFID = "CL_00001728";

	public EntityWitherSkull(World par1World)
	{
		super(par1World);
		this.setSize(0.3125F, 0.3125F);
	}

	public EntityWitherSkull(World par1World, EntityLivingBase par2EntityLivingBase, double par3, double par5, double par7)
	{
		super(par1World, par2EntityLivingBase, par3, par5, par7);
		this.setSize(0.3125F, 0.3125F);
	}

	protected float getMotionFactor()
	{
		return this.isInvulnerable() ? 0.73F : super.getMotionFactor();
	}

	@SideOnly(Side.CLIENT)
	public EntityWitherSkull(World par1World, double par2, double par4, double par6, double par8, double par10, double par12)
	{
		super(par1World, par2, par4, par6, par8, par10, par12);
		this.setSize(0.3125F, 0.3125F);
	}

	public boolean isBurning()
	{
		return false;
	}

	public float func_145772_a(Explosion p_145772_1_, World p_145772_2_, int p_145772_3_, int p_145772_4_, int p_145772_5_, Block p_145772_6_)
	{
		float f = super.func_145772_a(p_145772_1_, p_145772_2_, p_145772_3_, p_145772_4_, p_145772_5_, p_145772_6_);

		if (this.isInvulnerable() && p_145772_6_ != Blocks.bedrock && p_145772_6_ != Blocks.end_portal && p_145772_6_ != Blocks.end_portal_frame && p_145772_6_ != Blocks.command_block)
		{
			f = Math.min(0.8F, f);
		}

		return f;
	}

	protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
	{
		if (!this.worldObj.isRemote)
		{
			if (par1MovingObjectPosition.entityHit != null)
			{
				if (this.shootingEntity != null)
				{
					if (par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeMobDamage(this.shootingEntity), 8.0F) && !par1MovingObjectPosition.entityHit.isEntityAlive())
					{
						this.shootingEntity.heal(5.0F);
					}
				}
				else
				{
					par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.magic, 5.0F);
				}

				if (par1MovingObjectPosition.entityHit instanceof EntityLivingBase)
				{
					byte b0 = 0;

					if (this.worldObj.difficultySetting == EnumDifficulty.NORMAL)
					{
						b0 = 10;
					}
					else if (this.worldObj.difficultySetting == EnumDifficulty.HARD)
					{
						b0 = 40;
					}

					if (b0 > 0)
					{
						((EntityLivingBase)par1MovingObjectPosition.entityHit).addPotionEffect(new PotionEffect(Potion.wither.id, 20 * b0, 1));
					}
				}
			}

			this.worldObj.newExplosion(this, this.posX, this.posY, this.posZ, 1.0F, false, this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing"));
			this.setDead();
		}
	}

	public boolean canBeCollidedWith()
	{
		return false;
	}

	public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
	{
		return false;
	}

	protected void entityInit()
	{
		this.dataWatcher.addObject(10, Byte.valueOf((byte)0));
	}

	public boolean isInvulnerable()
	{
		return this.dataWatcher.getWatchableObjectByte(10) == 1;
	}

	public void setInvulnerable(boolean par1)
	{
		this.dataWatcher.updateObject(10, Byte.valueOf((byte)(par1 ? 1 : 0)));
	}
}