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