001package net.minecraft.entity.passive;
002
003import net.minecraft.block.material.Material;
004import net.minecraft.entity.EntityCreature;
005import net.minecraft.entity.player.EntityPlayer;
006import net.minecraft.util.DamageSource;
007import net.minecraft.world.World;
008
009public abstract class EntityWaterMob extends EntityCreature implements IAnimals
010{
011    public EntityWaterMob(World par1World)
012    {
013        super(par1World);
014    }
015
016    public boolean canBreatheUnderwater()
017    {
018        return true;
019    }
020
021    /**
022     * Checks if the entity's current position is a valid location to spawn this entity.
023     */
024    public boolean getCanSpawnHere()
025    {
026        return this.worldObj.checkNoEntityCollision(this.boundingBox);
027    }
028
029    /**
030     * Get number of ticks, at least during which the living entity will be silent.
031     */
032    public int getTalkInterval()
033    {
034        return 120;
035    }
036
037    /**
038     * Determines if an entity can be despawned, used on idle far away entities
039     */
040    protected boolean canDespawn()
041    {
042        return true;
043    }
044
045    /**
046     * Get the experience points the entity currently has.
047     */
048    protected int getExperiencePoints(EntityPlayer par1EntityPlayer)
049    {
050        return 1 + this.worldObj.rand.nextInt(3);
051    }
052
053    /**
054     * Gets called every tick from main Entity class
055     */
056    public void onEntityUpdate()
057    {
058        int i = this.getAir();
059        super.onEntityUpdate();
060
061        if (this.isEntityAlive() && !this.isInsideOfMaterial(Material.water))
062        {
063            --i;
064            this.setAir(i);
065
066            if (this.getAir() == -20)
067            {
068                this.setAir(0);
069                this.attackEntityFrom(DamageSource.drown, 2);
070            }
071        }
072        else
073        {
074            this.setAir(300);
075        }
076    }
077}