| 1 | package net.minecraft.entity.passive;
|
| 2 |
|
| 3 | import net.minecraft.block.material.Material;
|
| 4 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 5 | import net.minecraft.entity.ai.EntityAIBase;
|
| 6 | import net.minecraft.init.Items;
|
| 7 | import net.minecraft.item.EnumDyeColor;
|
| 8 | import net.minecraft.item.Item;
|
| 9 | import net.minecraft.item.ItemStack;
|
| 10 | import net.minecraft.util.MathHelper;
|
| 11 | import net.minecraft.world.World;
|
| 12 |
|
| 13 | public class EntitySquid extends EntityWaterMob
|
| 14 | {
|
| 15 | public float squidPitch;
|
| 16 | public float prevSquidPitch;
|
| 17 | public float squidYaw;
|
| 18 | public float prevSquidYaw;
|
| 19 |
|
| 20 | /**
|
| 21 | * appears to be rotation in radians; we already have pitch & yaw, so this completes the triumvirate.
|
| 22 | */
|
| 23 | public float squidRotation;
|
| 24 |
|
| 25 | /** previous squidRotation in radians */
|
| 26 | public float prevSquidRotation;
|
| 27 |
|
| 28 | /** angle of the tentacles in radians */
|
| 29 | public float tentacleAngle;
|
| 30 |
|
| 31 | /** the last calculated angle of the tentacles in radians */
|
| 32 | public float lastTentacleAngle;
|
| 33 | private float randomMotionSpeed;
|
| 34 |
|
| 35 | /** change in squidRotation in radians. */
|
| 36 | private float rotationVelocity;
|
| 37 | private float field_70871_bB;
|
| 38 | private float randomMotionVecX;
|
| 39 | private float randomMotionVecY;
|
| 40 | private float randomMotionVecZ;
|
| 41 |
|
| 42 | public EntitySquid(World worldIn)
|
| 43 | {
|
| 44 | super(worldIn);
|
| 45 | this.setSize(0.95F, 0.95F);
|
| 46 | this.rand.setSeed((long)(1 + this.getEntityId()));
|
| 47 | this.rotationVelocity = 1.0F / (this.rand.nextFloat() + 1.0F) * 0.2F;
|
| 48 | this.tasks.addTask(0, new EntitySquid.AIMoveRandom(this));
|
| 49 | }
|
| 50 |
|
| 51 | protected void applyEntityAttributes()
|
| 52 | {
|
| 53 | super.applyEntityAttributes();
|
| 54 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
|
| 55 | }
|
| 56 |
|
| 57 | public float getEyeHeight()
|
| 58 | {
|
| 59 | return this.height * 0.5F;
|
| 60 | }
|
| 61 |
|
| 62 | /**
|
| 63 | * Returns the sound this mob makes while it's alive.
|
| 64 | */
|
| 65 | protected String getLivingSound()
|
| 66 | {
|
| 67 | return null;
|
| 68 | }
|
| 69 |
|
| 70 | /**
|
| 71 | * Returns the sound this mob makes when it is hurt.
|
| 72 | */
|
| 73 | protected String getHurtSound()
|
| 74 | {
|
| 75 | return null;
|
| 76 | }
|
| 77 |
|
| 78 | /**
|
| 79 | * Returns the sound this mob makes on death.
|
| 80 | */
|
| 81 | protected String getDeathSound()
|
| 82 | {
|
| 83 | return null;
|
| 84 | }
|
| 85 |
|
| 86 | /**
|
| 87 | * Returns the volume for the sounds this mob makes.
|
| 88 | */
|
| 89 | protected float getSoundVolume()
|
| 90 | {
|
| 91 | return 0.4F;
|
| 92 | }
|
| 93 |
|
| 94 | protected Item getDropItem()
|
| 95 | {
|
| 96 | return null;
|
| 97 | }
|
| 98 |
|
| 99 | /**
|
| 100 | * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
|
| 101 | * prevent them from trampling crops
|
| 102 | */
|
| 103 | protected boolean canTriggerWalking()
|
| 104 | {
|
| 105 | return false;
|
| 106 | }
|
| 107 |
|
| 108 | /**
|
| 109 | * Drop 0-2 items of this living's type
|
| 110 | *
|
| 111 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 112 | * or tameable)
|
| 113 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 114 | */
|
| 115 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 116 | {
|
| 117 | int i = this.rand.nextInt(3 + lootingModifier) + 1;
|
| 118 |
|
| 119 | for (int j = 0; j < i; ++j)
|
| 120 | {
|
| 121 | this.entityDropItem(new ItemStack(Items.dye, 1, EnumDyeColor.BLACK.getDyeDamage()), 0.0F);
|
| 122 | }
|
| 123 | }
|
| 124 |
|
| 125 | /**
|
| 126 | * Checks if this entity is inside water (if inWater field is true as a result of handleWaterMovement() returning
|
| 127 | * true)
|
| 128 | */
|
| 129 | public boolean isInWater()
|
| 130 | {
|
| 131 | return this.worldObj.handleMaterialAcceleration(this.getEntityBoundingBox().expand(0.0D, -0.6000000238418579D, 0.0D), Material.water, this);
|
| 132 | }
|
| 133 |
|
| 134 | /**
|
| 135 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 136 | * use this to react to sunlight and start to burn.
|
| 137 | */
|
| 138 | public void onLivingUpdate()
|
| 139 | {
|
| 140 | super.onLivingUpdate();
|
| 141 | this.prevSquidPitch = this.squidPitch;
|
| 142 | this.prevSquidYaw = this.squidYaw;
|
| 143 | this.prevSquidRotation = this.squidRotation;
|
| 144 | this.lastTentacleAngle = this.tentacleAngle;
|
| 145 | this.squidRotation += this.rotationVelocity;
|
| 146 |
|
| 147 | if ((double)this.squidRotation > (Math.PI * 2D))
|
| 148 | {
|
| 149 | if (this.worldObj.isRemote)
|
| 150 | {
|
| 151 | this.squidRotation = ((float)Math.PI * 2F);
|
| 152 | }
|
| 153 | else
|
| 154 | {
|
| 155 | this.squidRotation = (float)((double)this.squidRotation - (Math.PI * 2D));
|
| 156 |
|
| 157 | if (this.rand.nextInt(10) == 0)
|
| 158 | {
|
| 159 | this.rotationVelocity = 1.0F / (this.rand.nextFloat() + 1.0F) * 0.2F;
|
| 160 | }
|
| 161 |
|
| 162 | this.worldObj.setEntityState(this, (byte)19);
|
| 163 | }
|
| 164 | }
|
| 165 |
|
| 166 | if (this.inWater)
|
| 167 | {
|
| 168 | if (this.squidRotation < (float)Math.PI)
|
| 169 | {
|
| 170 | float f = this.squidRotation / (float)Math.PI;
|
| 171 | this.tentacleAngle = MathHelper.sin(f * f * (float)Math.PI) * (float)Math.PI * 0.25F;
|
| 172 |
|
| 173 | if ((double)f > 0.75D)
|
| 174 | {
|
| 175 | this.randomMotionSpeed = 1.0F;
|
| 176 | this.field_70871_bB = 1.0F;
|
| 177 | }
|
| 178 | else
|
| 179 | {
|
| 180 | this.field_70871_bB *= 0.8F;
|
| 181 | }
|
| 182 | }
|
| 183 | else
|
| 184 | {
|
| 185 | this.tentacleAngle = 0.0F;
|
| 186 | this.randomMotionSpeed *= 0.9F;
|
| 187 | this.field_70871_bB *= 0.99F;
|
| 188 | }
|
| 189 |
|
| 190 | if (!this.worldObj.isRemote)
|
| 191 | {
|
| 192 | this.motionX = (double)(this.randomMotionVecX * this.randomMotionSpeed);
|
| 193 | this.motionY = (double)(this.randomMotionVecY * this.randomMotionSpeed);
|
| 194 | this.motionZ = (double)(this.randomMotionVecZ * this.randomMotionSpeed);
|
| 195 | }
|
| 196 |
|
| 197 | float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
|
| 198 | this.renderYawOffset += (-((float)MathHelper.atan2(this.motionX, this.motionZ)) * 180.0F / (float)Math.PI - this.renderYawOffset) * 0.1F;
|
| 199 | this.rotationYaw = this.renderYawOffset;
|
| 200 | this.squidYaw = (float)((double)this.squidYaw + Math.PI * (double)this.field_70871_bB * 1.5D);
|
| 201 | this.squidPitch += (-((float)MathHelper.atan2((double)f1, this.motionY)) * 180.0F / (float)Math.PI - this.squidPitch) * 0.1F;
|
| 202 | }
|
| 203 | else
|
| 204 | {
|
| 205 | this.tentacleAngle = MathHelper.abs(MathHelper.sin(this.squidRotation)) * (float)Math.PI * 0.25F;
|
| 206 |
|
| 207 | if (!this.worldObj.isRemote)
|
| 208 | {
|
| 209 | this.motionX = 0.0D;
|
| 210 | this.motionY -= 0.08D;
|
| 211 | this.motionY *= 0.9800000190734863D;
|
| 212 | this.motionZ = 0.0D;
|
| 213 | }
|
| 214 |
|
| 215 | this.squidPitch = (float)((double)this.squidPitch + (double)(-90.0F - this.squidPitch) * 0.02D);
|
| 216 | }
|
| 217 | }
|
| 218 |
|
| 219 | /**
|
| 220 | * Moves the entity based on the specified heading. Args: strafe, forward
|
| 221 | */
|
| 222 | public void moveEntityWithHeading(float strafe, float forward)
|
| 223 | {
|
| 224 | this.moveEntity(this.motionX, this.motionY, this.motionZ);
|
| 225 | }
|
| 226 |
|
| 227 | /**
|
| 228 | * Checks if the entity's current position is a valid location to spawn this entity.
|
| 229 | */
|
| 230 | public boolean getCanSpawnHere()
|
| 231 | {
|
| 232 | return this.posY > 45.0D && this.posY < (double)this.worldObj.getSeaLevel() && super.getCanSpawnHere();
|
| 233 | }
|
| 234 |
|
| 235 | public void handleStatusUpdate(byte id)
|
| 236 | {
|
| 237 | if (id == 19)
|
| 238 | {
|
| 239 | this.squidRotation = 0.0F;
|
| 240 | }
|
| 241 | else
|
| 242 | {
|
| 243 | super.handleStatusUpdate(id);
|
| 244 | }
|
| 245 | }
|
| 246 |
|
| 247 | public void func_175568_b(float randomMotionVecXIn, float randomMotionVecYIn, float randomMotionVecZIn)
|
| 248 | {
|
| 249 | this.randomMotionVecX = randomMotionVecXIn;
|
| 250 | this.randomMotionVecY = randomMotionVecYIn;
|
| 251 | this.randomMotionVecZ = randomMotionVecZIn;
|
| 252 | }
|
| 253 |
|
| 254 | public boolean func_175567_n()
|
| 255 | {
|
| 256 | return this.randomMotionVecX != 0.0F || this.randomMotionVecY != 0.0F || this.randomMotionVecZ != 0.0F;
|
| 257 | }
|
| 258 |
|
| 259 | static class AIMoveRandom extends EntityAIBase
|
| 260 | {
|
| 261 | private EntitySquid squid;
|
| 262 |
|
| 263 | public AIMoveRandom(EntitySquid p_i45859_1_)
|
| 264 | {
|
| 265 | this.squid = p_i45859_1_;
|
| 266 | }
|
| 267 |
|
| 268 | public boolean shouldExecute()
|
| 269 | {
|
| 270 | return true;
|
| 271 | }
|
| 272 |
|
| 273 | public void updateTask()
|
| 274 | {
|
| 275 | int i = this.squid.getAge();
|
| 276 |
|
| 277 | if (i > 100)
|
| 278 | {
|
| 279 | this.squid.func_175568_b(0.0F, 0.0F, 0.0F);
|
| 280 | }
|
| 281 | else if (this.squid.getRNG().nextInt(50) == 0 || !this.squid.inWater || !this.squid.func_175567_n())
|
| 282 | {
|
| 283 | float f = this.squid.getRNG().nextFloat() * (float)Math.PI * 2.0F;
|
| 284 | float f1 = MathHelper.cos(f) * 0.2F;
|
| 285 | float f2 = -0.1F + this.squid.getRNG().nextFloat() * 0.2F;
|
| 286 | float f3 = MathHelper.sin(f) * 0.2F;
|
| 287 | this.squid.func_175568_b(f1, f2, f3);
|
| 288 | }
|
| 289 | }
|
| 290 | }
|
| 291 | }
|
| 292 |
|