001 package net.minecraft.src; 002 003 public class EntitySlime extends EntityLiving implements IMob 004 { 005 public float field_70813_a; 006 public float field_70811_b; 007 public float field_70812_c; 008 009 /** the time between each jump of the slime */ 010 private int slimeJumpDelay = 0; 011 012 public EntitySlime(World par1World) 013 { 014 super(par1World); 015 this.texture = "/mob/slime.png"; 016 int var2 = 1 << this.rand.nextInt(3); 017 this.yOffset = 0.0F; 018 this.slimeJumpDelay = this.rand.nextInt(20) + 10; 019 this.setSlimeSize(var2); 020 } 021 022 protected void entityInit() 023 { 024 super.entityInit(); 025 this.dataWatcher.addObject(16, new Byte((byte)1)); 026 } 027 028 public void setSlimeSize(int par1) 029 { 030 this.dataWatcher.updateObject(16, new Byte((byte)par1)); 031 this.setSize(0.6F * (float)par1, 0.6F * (float)par1); 032 this.setPosition(this.posX, this.posY, this.posZ); 033 this.setEntityHealth(this.getMaxHealth()); 034 this.experienceValue = par1; 035 } 036 037 public int getMaxHealth() 038 { 039 int var1 = this.getSlimeSize(); 040 return var1 * var1; 041 } 042 043 /** 044 * Returns the size of the slime. 045 */ 046 public int getSlimeSize() 047 { 048 return this.dataWatcher.getWatchableObjectByte(16); 049 } 050 051 /** 052 * (abstract) Protected helper method to write subclass entity data to NBT. 053 */ 054 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) 055 { 056 super.writeEntityToNBT(par1NBTTagCompound); 057 par1NBTTagCompound.setInteger("Size", this.getSlimeSize() - 1); 058 } 059 060 /** 061 * (abstract) Protected helper method to read subclass entity data from NBT. 062 */ 063 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) 064 { 065 super.readEntityFromNBT(par1NBTTagCompound); 066 this.setSlimeSize(par1NBTTagCompound.getInteger("Size") + 1); 067 } 068 069 /** 070 * Returns the name of a particle effect that may be randomly created by EntitySlime.onUpdate() 071 */ 072 protected String getSlimeParticle() 073 { 074 return "slime"; 075 } 076 077 /** 078 * Returns the name of the sound played when the slime jumps. 079 */ 080 protected String getJumpSound() 081 { 082 return "mob.slime"; 083 } 084 085 /** 086 * Called to update the entity's position/logic. 087 */ 088 public void onUpdate() 089 { 090 if (!this.worldObj.isRemote && this.worldObj.difficultySetting == 0 && this.getSlimeSize() > 0) 091 { 092 this.isDead = true; 093 } 094 095 this.field_70811_b += (this.field_70813_a - this.field_70811_b) * 0.5F; 096 this.field_70812_c = this.field_70811_b; 097 boolean var1 = this.onGround; 098 super.onUpdate(); 099 100 if (this.onGround && !var1) 101 { 102 int var2 = this.getSlimeSize(); 103 104 for (int var3 = 0; var3 < var2 * 8; ++var3) 105 { 106 float var4 = this.rand.nextFloat() * (float)Math.PI * 2.0F; 107 float var5 = this.rand.nextFloat() * 0.5F + 0.5F; 108 float var6 = MathHelper.sin(var4) * (float)var2 * 0.5F * var5; 109 float var7 = MathHelper.cos(var4) * (float)var2 * 0.5F * var5; 110 this.worldObj.spawnParticle(this.getSlimeParticle(), this.posX + (double)var6, this.boundingBox.minY, this.posZ + (double)var7, 0.0D, 0.0D, 0.0D); 111 } 112 113 if (this.makesSoundOnLand()) 114 { 115 this.worldObj.playSoundAtEntity(this, this.getJumpSound(), this.getSoundVolume(), ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) / 0.8F); 116 } 117 118 this.field_70813_a = -0.5F; 119 } 120 else if (!this.onGround && var1) 121 { 122 this.field_70813_a = 1.0F; 123 } 124 125 this.func_70808_l(); 126 } 127 128 protected void updateEntityActionState() 129 { 130 this.despawnEntity(); 131 EntityPlayer var1 = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); 132 133 if (var1 != null) 134 { 135 this.faceEntity(var1, 10.0F, 20.0F); 136 } 137 138 if (this.onGround && this.slimeJumpDelay-- <= 0) 139 { 140 this.slimeJumpDelay = this.getJumpDelay(); 141 142 if (var1 != null) 143 { 144 this.slimeJumpDelay /= 3; 145 } 146 147 this.isJumping = true; 148 149 if (this.makesSoundOnJump()) 150 { 151 this.worldObj.playSoundAtEntity(this, this.getJumpSound(), this.getSoundVolume(), ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 0.8F); 152 } 153 154 this.moveStrafing = 1.0F - this.rand.nextFloat() * 2.0F; 155 this.moveForward = (float)(1 * this.getSlimeSize()); 156 } 157 else 158 { 159 this.isJumping = false; 160 161 if (this.onGround) 162 { 163 this.moveStrafing = this.moveForward = 0.0F; 164 } 165 } 166 } 167 168 protected void func_70808_l() 169 { 170 this.field_70813_a *= 0.6F; 171 } 172 173 /** 174 * Gets the amount of time the slime needs to wait between jumps. 175 */ 176 protected int getJumpDelay() 177 { 178 return this.rand.nextInt(20) + 10; 179 } 180 181 protected EntitySlime createInstance() 182 { 183 return new EntitySlime(this.worldObj); 184 } 185 186 /** 187 * Will get destroyed next tick. 188 */ 189 public void setDead() 190 { 191 int var1 = this.getSlimeSize(); 192 193 if (!this.worldObj.isRemote && var1 > 1 && this.getHealth() <= 0) 194 { 195 int var2 = 2 + this.rand.nextInt(3); 196 197 for (int var3 = 0; var3 < var2; ++var3) 198 { 199 float var4 = ((float)(var3 % 2) - 0.5F) * (float)var1 / 4.0F; 200 float var5 = ((float)(var3 / 2) - 0.5F) * (float)var1 / 4.0F; 201 EntitySlime var6 = this.createInstance(); 202 var6.setSlimeSize(var1 / 2); 203 var6.setLocationAndAngles(this.posX + (double)var4, this.posY + 0.5D, this.posZ + (double)var5, this.rand.nextFloat() * 360.0F, 0.0F); 204 this.worldObj.spawnEntityInWorld(var6); 205 } 206 } 207 208 super.setDead(); 209 } 210 211 /** 212 * Called by a player entity when they collide with an entity 213 */ 214 public void onCollideWithPlayer(EntityPlayer par1EntityPlayer) 215 { 216 if (this.canDamagePlayer()) 217 { 218 int var2 = this.getSlimeSize(); 219 220 if (this.canEntityBeSeen(par1EntityPlayer) && this.getDistanceSqToEntity(par1EntityPlayer) < 0.6D * (double)var2 * 0.6D * (double)var2 && par1EntityPlayer.attackEntityFrom(DamageSource.causeMobDamage(this), this.getAttackStrength())) 221 { 222 this.worldObj.playSoundAtEntity(this, "mob.slimeattack", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); 223 } 224 } 225 } 226 227 /** 228 * Indicates weather the slime is able to damage the player (based upon the slime's size) 229 */ 230 protected boolean canDamagePlayer() 231 { 232 return this.getSlimeSize() > 1; 233 } 234 235 /** 236 * Gets the amount of damage dealt to the player when "attacked" by the slime. 237 */ 238 protected int getAttackStrength() 239 { 240 return this.getSlimeSize(); 241 } 242 243 /** 244 * Returns the sound this mob makes when it is hurt. 245 */ 246 protected String getHurtSound() 247 { 248 return "mob.slime"; 249 } 250 251 /** 252 * Returns the sound this mob makes on death. 253 */ 254 protected String getDeathSound() 255 { 256 return "mob.slime"; 257 } 258 259 /** 260 * Returns the item ID for the item the mob drops on death. 261 */ 262 protected int getDropItemId() 263 { 264 return this.getSlimeSize() == 1 ? Item.slimeBall.shiftedIndex : 0; 265 } 266 267 /** 268 * Checks if the entity's current position is a valid location to spawn this entity. 269 */ 270 public boolean getCanSpawnHere() 271 { 272 Chunk var1 = this.worldObj.getChunkFromBlockCoords(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posZ)); 273 return this.worldObj.getWorldInfo().getTerrainType().handleSlimeSpawnReduction(rand, worldObj) ? false : ((this.getSlimeSize() == 1 || this.worldObj.difficultySetting > 0) && this.rand.nextInt(10) == 0 && var1.getRandomWithSeed(987234911L).nextInt(10) == 0 && this.posY < 40.0D ? super.getCanSpawnHere() : false); 274 } 275 276 /** 277 * Returns the volume for the sounds this mob makes. 278 */ 279 protected float getSoundVolume() 280 { 281 return 0.4F * (float)this.getSlimeSize(); 282 } 283 284 /** 285 * The speed it takes to move the entityliving's rotationPitch through the faceEntity method. This is only currently 286 * use in wolves. 287 */ 288 public int getVerticalFaceSpeed() 289 { 290 return 0; 291 } 292 293 /** 294 * Returns true if the slime makes a sound when it jumps (based upon the slime's size) 295 */ 296 protected boolean makesSoundOnJump() 297 { 298 return this.getSlimeSize() > 1; 299 } 300 301 /** 302 * Returns true if the slime makes a sound when it lands after a jump (based upon the slime's size) 303 */ 304 protected boolean makesSoundOnLand() 305 { 306 return this.getSlimeSize() > 2; 307 } 308 }