001 package net.minecraft.entity.passive;
002
003 import net.minecraft.block.material.Material;
004 import net.minecraft.item.Item;
005 import net.minecraft.item.ItemStack;
006 import net.minecraft.util.MathHelper;
007 import net.minecraft.world.World;
008
009 public class EntitySquid extends EntityWaterMob
010 {
011 public float field_70861_d = 0.0F;
012 public float field_70862_e = 0.0F;
013 public float field_70859_f = 0.0F;
014 public float field_70860_g = 0.0F;
015 public float field_70867_h = 0.0F;
016 public float field_70868_i = 0.0F;
017
018 /** angle of the tentacles in radians */
019 public float tentacleAngle = 0.0F;
020
021 /** the last calculated angle of the tentacles in radians */
022 public float lastTentacleAngle = 0.0F;
023 private float randomMotionSpeed = 0.0F;
024 private float field_70864_bA = 0.0F;
025 private float field_70871_bB = 0.0F;
026 private float randomMotionVecX = 0.0F;
027 private float randomMotionVecY = 0.0F;
028 private float randomMotionVecZ = 0.0F;
029
030 public EntitySquid(World par1World)
031 {
032 super(par1World);
033 this.texture = "/mob/squid.png";
034 this.setSize(0.95F, 0.95F);
035 this.field_70864_bA = 1.0F / (this.rand.nextFloat() + 1.0F) * 0.2F;
036 }
037
038 public int getMaxHealth()
039 {
040 return 10;
041 }
042
043 /**
044 * Returns the sound this mob makes while it's alive.
045 */
046 protected String getLivingSound()
047 {
048 return null;
049 }
050
051 /**
052 * Returns the sound this mob makes when it is hurt.
053 */
054 protected String getHurtSound()
055 {
056 return null;
057 }
058
059 /**
060 * Returns the sound this mob makes on death.
061 */
062 protected String getDeathSound()
063 {
064 return null;
065 }
066
067 /**
068 * Returns the volume for the sounds this mob makes.
069 */
070 protected float getSoundVolume()
071 {
072 return 0.4F;
073 }
074
075 /**
076 * Returns the item ID for the item the mob drops on death.
077 */
078 protected int getDropItemId()
079 {
080 return 0;
081 }
082
083 /**
084 * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
085 * par2 - Level of Looting used to kill this mob.
086 */
087 protected void dropFewItems(boolean par1, int par2)
088 {
089 int var3 = this.rand.nextInt(3 + par2) + 1;
090
091 for (int var4 = 0; var4 < var3; ++var4)
092 {
093 this.entityDropItem(new ItemStack(Item.dyePowder, 1, 0), 0.0F);
094 }
095 }
096
097 /**
098 * Checks if this entity is inside water (if inWater field is true as a result of handleWaterMovement() returning
099 * true)
100 */
101 public boolean isInWater()
102 {
103 return this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(0.0D, -0.6000000238418579D, 0.0D), Material.water, this);
104 }
105
106 /**
107 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
108 * use this to react to sunlight and start to burn.
109 */
110 public void onLivingUpdate()
111 {
112 super.onLivingUpdate();
113 this.field_70862_e = this.field_70861_d;
114 this.field_70860_g = this.field_70859_f;
115 this.field_70868_i = this.field_70867_h;
116 this.lastTentacleAngle = this.tentacleAngle;
117 this.field_70867_h += this.field_70864_bA;
118
119 if (this.field_70867_h > ((float)Math.PI * 2F))
120 {
121 this.field_70867_h -= ((float)Math.PI * 2F);
122
123 if (this.rand.nextInt(10) == 0)
124 {
125 this.field_70864_bA = 1.0F / (this.rand.nextFloat() + 1.0F) * 0.2F;
126 }
127 }
128
129 if (this.isInWater())
130 {
131 float var1;
132
133 if (this.field_70867_h < (float)Math.PI)
134 {
135 var1 = this.field_70867_h / (float)Math.PI;
136 this.tentacleAngle = MathHelper.sin(var1 * var1 * (float)Math.PI) * (float)Math.PI * 0.25F;
137
138 if ((double)var1 > 0.75D)
139 {
140 this.randomMotionSpeed = 1.0F;
141 this.field_70871_bB = 1.0F;
142 }
143 else
144 {
145 this.field_70871_bB *= 0.8F;
146 }
147 }
148 else
149 {
150 this.tentacleAngle = 0.0F;
151 this.randomMotionSpeed *= 0.9F;
152 this.field_70871_bB *= 0.99F;
153 }
154
155 if (!this.worldObj.isRemote)
156 {
157 this.motionX = (double)(this.randomMotionVecX * this.randomMotionSpeed);
158 this.motionY = (double)(this.randomMotionVecY * this.randomMotionSpeed);
159 this.motionZ = (double)(this.randomMotionVecZ * this.randomMotionSpeed);
160 }
161
162 var1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
163 this.renderYawOffset += (-((float)Math.atan2(this.motionX, this.motionZ)) * 180.0F / (float)Math.PI - this.renderYawOffset) * 0.1F;
164 this.rotationYaw = this.renderYawOffset;
165 this.field_70859_f += (float)Math.PI * this.field_70871_bB * 1.5F;
166 this.field_70861_d += (-((float)Math.atan2((double)var1, this.motionY)) * 180.0F / (float)Math.PI - this.field_70861_d) * 0.1F;
167 }
168 else
169 {
170 this.tentacleAngle = MathHelper.abs(MathHelper.sin(this.field_70867_h)) * (float)Math.PI * 0.25F;
171
172 if (!this.worldObj.isRemote)
173 {
174 this.motionX = 0.0D;
175 this.motionY -= 0.08D;
176 this.motionY *= 0.9800000190734863D;
177 this.motionZ = 0.0D;
178 }
179
180 this.field_70861_d = (float)((double)this.field_70861_d + (double)(-90.0F - this.field_70861_d) * 0.02D);
181 }
182 }
183
184 /**
185 * Moves the entity based on the specified heading. Args: strafe, forward
186 */
187 public void moveEntityWithHeading(float par1, float par2)
188 {
189 this.moveEntity(this.motionX, this.motionY, this.motionZ);
190 }
191
192 protected void updateEntityActionState()
193 {
194 ++this.entityAge;
195
196 if (this.entityAge > 100)
197 {
198 this.randomMotionVecX = this.randomMotionVecY = this.randomMotionVecZ = 0.0F;
199 }
200 else if (this.rand.nextInt(50) == 0 || !this.inWater || this.randomMotionVecX == 0.0F && this.randomMotionVecY == 0.0F && this.randomMotionVecZ == 0.0F)
201 {
202 float var1 = this.rand.nextFloat() * (float)Math.PI * 2.0F;
203 this.randomMotionVecX = MathHelper.cos(var1) * 0.2F;
204 this.randomMotionVecY = -0.1F + this.rand.nextFloat() * 0.2F;
205 this.randomMotionVecZ = MathHelper.sin(var1) * 0.2F;
206 }
207
208 this.despawnEntity();
209 }
210
211 /**
212 * Checks if the entity's current position is a valid location to spawn this entity.
213 */
214 public boolean getCanSpawnHere()
215 {
216 return this.posY > 45.0D && this.posY < 63.0D && super.getCanSpawnHere();
217 }
218 }