001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 006 public class EntitySpider extends EntityMob 007 { 008 public EntitySpider(World par1World) 009 { 010 super(par1World); 011 this.texture = "/mob/spider.png"; 012 this.setSize(1.4F, 0.9F); 013 this.moveSpeed = 0.8F; 014 } 015 016 protected void entityInit() 017 { 018 super.entityInit(); 019 this.dataWatcher.addObject(16, new Byte((byte)0)); 020 } 021 022 /** 023 * Called to update the entity's position/logic. 024 */ 025 public void onUpdate() 026 { 027 super.onUpdate(); 028 029 if (!this.worldObj.isRemote) 030 { 031 this.setBesideClimbableBlock(this.isCollidedHorizontally); 032 } 033 } 034 035 public int getMaxHealth() 036 { 037 return 16; 038 } 039 040 /** 041 * Returns the Y offset from the entity's position for any entity riding this one. 042 */ 043 public double getMountedYOffset() 044 { 045 return (double)this.height * 0.75D - 0.5D; 046 } 047 048 /** 049 * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to 050 * prevent them from trampling crops 051 */ 052 protected boolean canTriggerWalking() 053 { 054 return false; 055 } 056 057 /** 058 * Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking 059 * (Animals, Spiders at day, peaceful PigZombies). 060 */ 061 protected Entity findPlayerToAttack() 062 { 063 float var1 = this.getBrightness(1.0F); 064 065 if (var1 < 0.5F) 066 { 067 double var2 = 16.0D; 068 return this.worldObj.getClosestVulnerablePlayerToEntity(this, var2); 069 } 070 else 071 { 072 return null; 073 } 074 } 075 076 /** 077 * Returns the sound this mob makes while it's alive. 078 */ 079 protected String getLivingSound() 080 { 081 return "mob.spider"; 082 } 083 084 /** 085 * Returns the sound this mob makes when it is hurt. 086 */ 087 protected String getHurtSound() 088 { 089 return "mob.spider"; 090 } 091 092 /** 093 * Returns the sound this mob makes on death. 094 */ 095 protected String getDeathSound() 096 { 097 return "mob.spiderdeath"; 098 } 099 100 /** 101 * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack. 102 */ 103 protected void attackEntity(Entity par1Entity, float par2) 104 { 105 float var3 = this.getBrightness(1.0F); 106 107 if (var3 > 0.5F && this.rand.nextInt(100) == 0) 108 { 109 this.entityToAttack = null; 110 } 111 else 112 { 113 if (par2 > 2.0F && par2 < 6.0F && this.rand.nextInt(10) == 0) 114 { 115 if (this.onGround) 116 { 117 double var4 = par1Entity.posX - this.posX; 118 double var6 = par1Entity.posZ - this.posZ; 119 float var8 = MathHelper.sqrt_double(var4 * var4 + var6 * var6); 120 this.motionX = var4 / (double)var8 * 0.5D * 0.800000011920929D + this.motionX * 0.20000000298023224D; 121 this.motionZ = var6 / (double)var8 * 0.5D * 0.800000011920929D + this.motionZ * 0.20000000298023224D; 122 this.motionY = 0.4000000059604645D; 123 } 124 } 125 else 126 { 127 super.attackEntity(par1Entity, par2); 128 } 129 } 130 } 131 132 /** 133 * Returns the item ID for the item the mob drops on death. 134 */ 135 protected int getDropItemId() 136 { 137 return Item.silk.shiftedIndex; 138 } 139 140 /** 141 * Drop 0-2 items of this living's type 142 */ 143 protected void dropFewItems(boolean par1, int par2) 144 { 145 super.dropFewItems(par1, par2); 146 147 if (par1 && (this.rand.nextInt(3) == 0 || this.rand.nextInt(1 + par2) > 0)) 148 { 149 this.dropItem(Item.spiderEye.shiftedIndex, 1); 150 } 151 } 152 153 /** 154 * returns true if this entity is by a ladder, false otherwise 155 */ 156 public boolean isOnLadder() 157 { 158 return this.isBesideClimbableBlock(); 159 } 160 161 /** 162 * Sets the Entity inside a web block. 163 */ 164 public void setInWeb() {} 165 166 @SideOnly(Side.CLIENT) 167 168 /** 169 * How large the spider should be scaled. 170 */ 171 public float spiderScaleAmount() 172 { 173 return 1.0F; 174 } 175 176 /** 177 * Get this Entity's EnumCreatureAttribute 178 */ 179 public EnumCreatureAttribute getCreatureAttribute() 180 { 181 return EnumCreatureAttribute.ARTHROPOD; 182 } 183 184 public boolean isPotionApplicable(PotionEffect par1PotionEffect) 185 { 186 return par1PotionEffect.getPotionID() == Potion.poison.id ? false : super.isPotionApplicable(par1PotionEffect); 187 } 188 189 /** 190 * Returns true if the WatchableObject (Byte) is 0x01 otherwise returns false. The WatchableObject is updated using 191 * setBesideClimableBlock. 192 */ 193 public boolean isBesideClimbableBlock() 194 { 195 return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0; 196 } 197 198 /** 199 * Updates the WatchableObject (Byte) created in entityInit(), setting it to 0x01 if par1 is true or 0x00 if it is 200 * false. 201 */ 202 public void setBesideClimbableBlock(boolean par1) 203 { 204 byte var2 = this.dataWatcher.getWatchableObjectByte(16); 205 206 if (par1) 207 { 208 var2 = (byte)(var2 | 1); 209 } 210 else 211 { 212 var2 &= -2; 213 } 214 215 this.dataWatcher.updateObject(16, Byte.valueOf(var2)); 216 } 217 }