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 (super.attackEntityFrom(par1DamageSource, par2)) 057 { 058 Entity var3 = par1DamageSource.getEntity(); 059 060 if (this.riddenByEntity != var3 && this.ridingEntity != var3) 061 { 062 if (var3 != this) 063 { 064 this.entityToAttack = var3; 065 } 066 067 return true; 068 } 069 else 070 { 071 return true; 072 } 073 } 074 else 075 { 076 return false; 077 } 078 } 079 080 public boolean attackEntityAsMob(Entity par1Entity) 081 { 082 int var2 = this.getAttackStrength(par1Entity); 083 084 if (this.isPotionActive(Potion.damageBoost)) 085 { 086 var2 += 3 << this.getActivePotionEffect(Potion.damageBoost).getAmplifier(); 087 } 088 089 if (this.isPotionActive(Potion.weakness)) 090 { 091 var2 -= 2 << this.getActivePotionEffect(Potion.weakness).getAmplifier(); 092 } 093 094 int var3 = 0; 095 096 if (par1Entity instanceof EntityLiving) 097 { 098 var2 += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLiving)par1Entity); 099 var3 += EnchantmentHelper.getKnockbackModifier(this, (EntityLiving)par1Entity); 100 } 101 102 boolean var4 = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), var2); 103 104 if (var4) 105 { 106 if (var3 > 0) 107 { 108 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)); 109 this.motionX *= 0.6D; 110 this.motionZ *= 0.6D; 111 } 112 113 int var5 = EnchantmentHelper.getFireAspectModifier(this, (EntityLiving)par1Entity); 114 115 if (var5 > 0) 116 { 117 par1Entity.setFire(var5 * 4); 118 } 119 } 120 121 return var4; 122 } 123 124 /** 125 * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack. 126 */ 127 protected void attackEntity(Entity par1Entity, float par2) 128 { 129 if (this.attackTime <= 0 && par2 < 2.0F && par1Entity.boundingBox.maxY > this.boundingBox.minY && par1Entity.boundingBox.minY < this.boundingBox.maxY) 130 { 131 this.attackTime = 20; 132 this.attackEntityAsMob(par1Entity); 133 } 134 } 135 136 /** 137 * Takes a coordinate in and returns a weight to determine how likely this creature will try to path to the block. 138 * Args: x, y, z 139 */ 140 public float getBlockPathWeight(int par1, int par2, int par3) 141 { 142 return 0.5F - this.worldObj.getLightBrightness(par1, par2, par3); 143 } 144 145 /** 146 * Checks to make sure the light is not too bright where the mob is spawning 147 */ 148 protected boolean isValidLightLevel() 149 { 150 int var1 = MathHelper.floor_double(this.posX); 151 int var2 = MathHelper.floor_double(this.boundingBox.minY); 152 int var3 = MathHelper.floor_double(this.posZ); 153 154 if (this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, var1, var2, var3) > this.rand.nextInt(32)) 155 { 156 return false; 157 } 158 else 159 { 160 int var4 = this.worldObj.getBlockLightValue(var1, var2, var3); 161 162 if (this.worldObj.isThundering()) 163 { 164 int var5 = this.worldObj.skylightSubtracted; 165 this.worldObj.skylightSubtracted = 10; 166 var4 = this.worldObj.getBlockLightValue(var1, var2, var3); 167 this.worldObj.skylightSubtracted = var5; 168 } 169 170 return var4 <= this.rand.nextInt(8); 171 } 172 } 173 174 /** 175 * Checks if the entity's current position is a valid location to spawn this entity. 176 */ 177 public boolean getCanSpawnHere() 178 { 179 return this.isValidLightLevel() && super.getCanSpawnHere(); 180 } 181 182 /** 183 * Returns the amount of damage a mob should deal. 184 */ 185 public int getAttackStrength(Entity par1Entity) 186 { 187 return 2; 188 } 189 }