    001    package net.minecraft.entity.monster;
    002
    003    import net.minecraft.enchantment.EnchantmentHelper;
    004    import net.minecraft.entity.Entity;
    005    import net.minecraft.entity.EntityCreature;
    006    import net.minecraft.entity.EntityLiving;
    007    import net.minecraft.entity.player.EntityPlayer;
    008    import net.minecraft.potion.Potion;
    009    import net.minecraft.util.DamageSource;
    010    import net.minecraft.util.MathHelper;
    011    import net.minecraft.world.EnumSkyBlock;
    012    import net.minecraft.world.World;
    013
    014    public abstract class EntityMob extends EntityCreature implements IMob
    015    {
    016        public EntityMob(World par1World)
    017        {
    018            super(par1World);
    019            this.experienceValue = 5;
    020        }
    021
    022        /**
    023         * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
    024         * use this to react to sunlight and start to burn.
    025         */
    026        public void onLivingUpdate()
    027        {
    028            this.updateArmSwingProgress();
    029            float var1 = this.getBrightness(1.0F);
    030
    031            if (var1 > 0.5F)
    032            {
    033                this.entityAge += 2;
    034            }
    035
    036            super.onLivingUpdate();
    037        }
    038
    039        /**
    040         * Called to update the entity's position/logic.
    041         */
    042        public void onUpdate()
    043        {
    044            super.onUpdate();
    045
    046            if (!this.worldObj.isRemote && this.worldObj.difficultySetting == 0)
    047            {
    048                this.setDead();
    049            }
    050        }
    051
    052        /**
    053         * Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking
    054         * (Animals, Spiders at day, peaceful PigZombies).
    055         */
    056        protected Entity findPlayerToAttack()
    057        {
    058            EntityPlayer var1 = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D);
    059            return var1 != null && this.canEntityBeSeen(var1) ? var1 : null;
    060        }
    061
    062        /**
    063         * Called when the entity is attacked.
    064         */
    065        public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    066        {
    067            if (this.func_85032_ar())
    068            {
    069                return false;
    070            }
    071            else if (super.attackEntityFrom(par1DamageSource, par2))
    072            {
    073                Entity var3 = par1DamageSource.getEntity();
    074
    075                if (this.riddenByEntity != var3 && this.ridingEntity != var3)
    076                {
    077                    if (var3 != this)
    078                    {
    079                        this.entityToAttack = var3;
    080                    }
    081
    082                    return true;
    083                }
    084                else
    085                {
    086                    return true;
    087                }
    088            }
    089            else
    090            {
    091                return false;
    092            }
    093        }
    094
    095        public boolean attackEntityAsMob(Entity par1Entity)
    096        {
    097            int var2 = this.getAttackStrength(par1Entity);
    098
    099            if (this.isPotionActive(Potion.damageBoost))
    100            {
    101                var2 += 3 << this.getActivePotionEffect(Potion.damageBoost).getAmplifier();
    102            }
    103
    104            if (this.isPotionActive(Potion.weakness))
    105            {
    106                var2 -= 2 << this.getActivePotionEffect(Potion.weakness).getAmplifier();
    107            }
    108
    109            int var3 = 0;
    110
    111            if (par1Entity instanceof EntityLiving)
    112            {
    113                var2 += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLiving)par1Entity);
    114                var3 += EnchantmentHelper.getKnockbackModifier(this, (EntityLiving)par1Entity);
    115            }
    116
    117            boolean var4 = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), var2);
    118
    119            if (var4)
    120            {
    121                if (var3 > 0)
    122                {
    123                    par1Entity.addVelocity((double)(-MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F) * (float)var3 * 0.5F), 0.1D, (double)(MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F) * (float)var3 * 0.5F));
    124                    this.motionX *= 0.6D;
    125                    this.motionZ *= 0.6D;
    126                }
    127
    128                int var5 = EnchantmentHelper.func_90036_a(this);
    129
    130                if (var5 > 0)
    131                {
    132                    par1Entity.setFire(var5 * 4);
    133                }
    134            }
    135
    136            return var4;
    137        }
    138
    139        /**
    140         * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack.
    141         */
    142        protected void attackEntity(Entity par1Entity, float par2)
    143        {
    144            if (this.attackTime <= 0 && par2 < 2.0F && par1Entity.boundingBox.maxY > this.boundingBox.minY && par1Entity.boundingBox.minY < this.boundingBox.maxY)
    145            {
    146                this.attackTime = 20;
    147                this.attackEntityAsMob(par1Entity);
    148            }
    149        }
    150
    151        /**
    152         * Takes a coordinate in and returns a weight to determine how likely this creature will try to path to the block.
    153         * Args: x, y, z
    154         */
    155        public float getBlockPathWeight(int par1, int par2, int par3)
    156        {
    157            return 0.5F - this.worldObj.getLightBrightness(par1, par2, par3);
    158        }
    159
    160        /**
    161         * Checks to make sure the light is not too bright where the mob is spawning
    162         */
    163        protected boolean isValidLightLevel()
    164        {
    165            int var1 = MathHelper.floor_double(this.posX);
    166            int var2 = MathHelper.floor_double(this.boundingBox.minY);
    167            int var3 = MathHelper.floor_double(this.posZ);
    168
    169            if (this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, var1, var2, var3) > this.rand.nextInt(32))
    170            {
    171                return false;
    172            }
    173            else
    174            {
    175                int var4 = this.worldObj.getBlockLightValue(var1, var2, var3);
    176
    177                if (this.worldObj.isThundering())
    178                {
    179                    int var5 = this.worldObj.skylightSubtracted;
    180                    this.worldObj.skylightSubtracted = 10;
    181                    var4 = this.worldObj.getBlockLightValue(var1, var2, var3);
    182                    this.worldObj.skylightSubtracted = var5;
    183                }
    184
    185                return var4 <= this.rand.nextInt(8);
    186            }
    187        }
    188
    189        /**
    190         * Checks if the entity's current position is a valid location to spawn this entity.
    191         */
    192        public boolean getCanSpawnHere()
    193        {
    194            return this.isValidLightLevel() && super.getCanSpawnHere();
    195        }
    196
    197        /**
    198         * Returns the amount of damage a mob should deal.
    199         */
    200        public int getAttackStrength(Entity par1Entity)
    201        {
    202            return 2;
    203        }
    204    }