001 package net.minecraft.src;
002
003 public class EntitySilverfish extends EntityMob
004 {
005 /**
006 * A cooldown before this entity will search for another Silverfish to join them in battle.
007 */
008 private int allySummonCooldown;
009
010 public EntitySilverfish(World par1World)
011 {
012 super(par1World);
013 this.texture = "/mob/silverfish.png";
014 this.setSize(0.3F, 0.7F);
015 this.moveSpeed = 0.6F;
016 }
017
018 public int getMaxHealth()
019 {
020 return 8;
021 }
022
023 /**
024 * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
025 * prevent them from trampling crops
026 */
027 protected boolean canTriggerWalking()
028 {
029 return false;
030 }
031
032 /**
033 * Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking
034 * (Animals, Spiders at day, peaceful PigZombies).
035 */
036 protected Entity findPlayerToAttack()
037 {
038 double var1 = 8.0D;
039 return this.worldObj.getClosestVulnerablePlayerToEntity(this, var1);
040 }
041
042 /**
043 * Returns the sound this mob makes while it's alive.
044 */
045 protected String getLivingSound()
046 {
047 return "mob.silverfish.say";
048 }
049
050 /**
051 * Returns the sound this mob makes when it is hurt.
052 */
053 protected String getHurtSound()
054 {
055 return "mob.silverfish.hit";
056 }
057
058 /**
059 * Returns the sound this mob makes on death.
060 */
061 protected String getDeathSound()
062 {
063 return "mob.silverfish.kill";
064 }
065
066 /**
067 * Called when the entity is attacked.
068 */
069 public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
070 {
071 if (this.func_85032_ar())
072 {
073 return false;
074 }
075 else
076 {
077 if (this.allySummonCooldown <= 0 && (par1DamageSource instanceof EntityDamageSource || par1DamageSource == DamageSource.magic))
078 {
079 this.allySummonCooldown = 20;
080 }
081
082 return super.attackEntityFrom(par1DamageSource, par2);
083 }
084 }
085
086 /**
087 * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack.
088 */
089 protected void attackEntity(Entity par1Entity, float par2)
090 {
091 if (this.attackTime <= 0 && par2 < 1.2F && par1Entity.boundingBox.maxY > this.boundingBox.minY && par1Entity.boundingBox.minY < this.boundingBox.maxY)
092 {
093 this.attackTime = 20;
094 par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), this.getAttackStrength(par1Entity));
095 }
096 }
097
098 /**
099 * Plays step sound at given x, y, z for the entity
100 */
101 protected void playStepSound(int par1, int par2, int par3, int par4)
102 {
103 this.func_85030_a("mob.silverfish.step", 0.15F, 1.0F);
104 }
105
106 /**
107 * Returns the item ID for the item the mob drops on death.
108 */
109 protected int getDropItemId()
110 {
111 return 0;
112 }
113
114 /**
115 * Called to update the entity's position/logic.
116 */
117 public void onUpdate()
118 {
119 this.renderYawOffset = this.rotationYaw;
120 super.onUpdate();
121 }
122
123 protected void updateEntityActionState()
124 {
125 super.updateEntityActionState();
126
127 if (!this.worldObj.isRemote)
128 {
129 int var1;
130 int var2;
131 int var3;
132 int var5;
133
134 if (this.allySummonCooldown > 0)
135 {
136 --this.allySummonCooldown;
137
138 if (this.allySummonCooldown == 0)
139 {
140 var1 = MathHelper.floor_double(this.posX);
141 var2 = MathHelper.floor_double(this.posY);
142 var3 = MathHelper.floor_double(this.posZ);
143 boolean var4 = false;
144
145 for (var5 = 0; !var4 && var5 <= 5 && var5 >= -5; var5 = var5 <= 0 ? 1 - var5 : 0 - var5)
146 {
147 for (int var6 = 0; !var4 && var6 <= 10 && var6 >= -10; var6 = var6 <= 0 ? 1 - var6 : 0 - var6)
148 {
149 for (int var7 = 0; !var4 && var7 <= 10 && var7 >= -10; var7 = var7 <= 0 ? 1 - var7 : 0 - var7)
150 {
151 int var8 = this.worldObj.getBlockId(var1 + var6, var2 + var5, var3 + var7);
152
153 if (var8 == Block.silverfish.blockID)
154 {
155 this.worldObj.playAuxSFX(2001, var1 + var6, var2 + var5, var3 + var7, Block.silverfish.blockID + (this.worldObj.getBlockMetadata(var1 + var6, var2 + var5, var3 + var7) << 12));
156 this.worldObj.setBlockWithNotify(var1 + var6, var2 + var5, var3 + var7, 0);
157 Block.silverfish.onBlockDestroyedByPlayer(this.worldObj, var1 + var6, var2 + var5, var3 + var7, 0);
158
159 if (this.rand.nextBoolean())
160 {
161 var4 = true;
162 break;
163 }
164 }
165 }
166 }
167 }
168 }
169 }
170
171 if (this.entityToAttack == null && !this.hasPath())
172 {
173 var1 = MathHelper.floor_double(this.posX);
174 var2 = MathHelper.floor_double(this.posY + 0.5D);
175 var3 = MathHelper.floor_double(this.posZ);
176 int var9 = this.rand.nextInt(6);
177 var5 = this.worldObj.getBlockId(var1 + Facing.offsetsXForSide[var9], var2 + Facing.offsetsYForSide[var9], var3 + Facing.offsetsZForSide[var9]);
178
179 if (BlockSilverfish.getPosingIdByMetadata(var5))
180 {
181 this.worldObj.setBlockAndMetadataWithNotify(var1 + Facing.offsetsXForSide[var9], var2 + Facing.offsetsYForSide[var9], var3 + Facing.offsetsZForSide[var9], Block.silverfish.blockID, BlockSilverfish.getMetadataForBlockType(var5));
182 this.spawnExplosionParticle();
183 this.setDead();
184 }
185 else
186 {
187 this.updateWanderPath();
188 }
189 }
190 else if (this.entityToAttack != null && !this.hasPath())
191 {
192 this.entityToAttack = null;
193 }
194 }
195 }
196
197 /**
198 * Takes a coordinate in and returns a weight to determine how likely this creature will try to path to the block.
199 * Args: x, y, z
200 */
201 public float getBlockPathWeight(int par1, int par2, int par3)
202 {
203 return this.worldObj.getBlockId(par1, par2 - 1, par3) == Block.stone.blockID ? 10.0F : super.getBlockPathWeight(par1, par2, par3);
204 }
205
206 /**
207 * Checks to make sure the light is not too bright where the mob is spawning
208 */
209 protected boolean isValidLightLevel()
210 {
211 return true;
212 }
213
214 /**
215 * Checks if the entity's current position is a valid location to spawn this entity.
216 */
217 public boolean getCanSpawnHere()
218 {
219 if (super.getCanSpawnHere())
220 {
221 EntityPlayer var1 = this.worldObj.getClosestPlayerToEntity(this, 5.0D);
222 return var1 == null;
223 }
224 else
225 {
226 return false;
227 }
228 }
229
230 /**
231 * Returns the amount of damage a mob should deal.
232 */
233 public int getAttackStrength(Entity par1Entity)
234 {
235 return 1;
236 }
237
238 /**
239 * Get this Entity's EnumCreatureAttribute
240 */
241 public EnumCreatureAttribute getCreatureAttribute()
242 {
243 return EnumCreatureAttribute.ARTHROPOD;
244 }
245 }