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