package net.minecraft.entity.monster;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
public class EntityPigZombie extends EntityZombie
{
/** Above zero if this PigZombie is Angry. */
private int angerLevel = 0;
/** A random delay until this PigZombie next makes a sound. */
private int randomSoundDelay = 0;
public EntityPigZombie(World par1World)
{
super(par1World);
this.texture = "/mob/pigzombie.png";
this.moveSpeed = 0.5F;
this.isImmuneToFire = true;
}
/**
* Returns true if the newer Entity AI code should be run
*/
protected boolean isAIEnabled()
{
return false;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
this.moveSpeed = this.entityToAttack != null ? 0.95F : 0.5F;
if (this.randomSoundDelay > 0 && --this.randomSoundDelay == 0)
{
this.playSound("mob.zombiepig.zpigangry", this.getSoundVolume() * 2.0F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 1.8F);
}
super.onUpdate();
}
@SideOnly(Side.CLIENT)
/**
* Returns the texture's file path as a String.
*/
public String getTexture()
{
return "/mob/pigzombie.png";
}
/**
* Checks if the entity's current position is a valid location to spawn this entity.
*/
public boolean getCanSpawnHere()
{
return this.worldObj.difficultySetting > 0 && this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox);
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeEntityToNBT(par1NBTTagCompound);
par1NBTTagCompound.setShort("Anger", (short)this.angerLevel);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readEntityFromNBT(par1NBTTagCompound);
this.angerLevel = par1NBTTagCompound.getShort("Anger");
}
/**
* Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking
* (Animals, Spiders at day, peaceful PigZombies).
*/
protected Entity findPlayerToAttack()
{
return this.angerLevel == 0 ? null : super.findPlayerToAttack();
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
{
if (this.isEntityInvulnerable())
{
return false;
}
else
{
Entity entity = par1DamageSource.getEntity();
if (entity instanceof EntityPlayer)
{
List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(32.0D, 32.0D, 32.0D));
for (int j = 0; j < list.size(); ++j)
{
Entity entity1 = (Entity)list.get(j);
if (entity1 instanceof EntityPigZombie)
{
EntityPigZombie entitypigzombie = (EntityPigZombie)entity1;
entitypigzombie.becomeAngryAt(entity);
}
}
this.becomeAngryAt(entity);
}
return super.attackEntityFrom(par1DamageSource, par2);
}
}
/**
* Causes this PigZombie to become angry at the supplied Entity (which will be a player).
*/
private void becomeAngryAt(Entity par1Entity)
{
this.entityToAttack = par1Entity;
this.angerLevel = 400 + this.rand.nextInt(400);
this.randomSoundDelay = this.rand.nextInt(40);
}
/**
* Returns the sound this mob makes while it's alive.
*/
protected String getLivingSound()
{
return "mob.zombiepig.zpig";
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound()
{
return "mob.zombiepig.zpighurt";
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound()
{
return "mob.zombiepig.zpigdeath";
}
/**
* Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
* par2 - Level of Looting used to kill this mob.
*/
protected void dropFewItems(boolean par1, int par2)
{
int j = this.rand.nextInt(2 + par2);
int k;
for (k = 0; k < j; ++k)
{
this.dropItem(Item.rottenFlesh.itemID, 1);
}
j = this.rand.nextInt(2 + par2);
for (k = 0; k < j; ++k)
{
this.dropItem(Item.goldNugget.itemID, 1);
}
}
/**
* Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
*/
public boolean interact(EntityPlayer par1EntityPlayer)
{
return false;
}
protected void dropRareDrop(int par1)
{
this.dropItem(Item.ingotGold.itemID, 1);
}
/**
* Returns the item ID for the item the mob drops on death.
*/
protected int getDropItemId()
{
return Item.rottenFlesh.itemID;
}
/**
* Makes entity wear random armor based on difficulty
*/
protected void addRandomArmor()
{
this.setCurrentItemOrArmor(0, new ItemStack(Item.swordGold));
}
/**
* Initialize this creature.
*/
public void initCreature()
{
super.initCreature();
this.setVillager(false);
}
/**
* Returns the amount of damage a mob should deal.
*/
public int getAttackStrength(Entity par1Entity)
{
ItemStack itemstack = this.getHeldItem();
int i = 5;
if (itemstack != null)
{
i += itemstack.getDamageVsEntity(this);
}
return i;
}
}