    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
    085         */
    086        protected void dropFewItems(boolean par1, int par2)
    087        {
    088            int var3 = this.rand.nextInt(3 + par2) + 1;
    089
    090            for (int var4 = 0; var4 < var3; ++var4)
    091            {
    092                this.entityDropItem(new ItemStack(Item.dyePowder, 1, 0), 0.0F);
    093            }
    094        }
    095
    096        /**
    097         * Checks if this entity is inside water (if inWater field is true as a result of handleWaterMovement() returning
    098         * true)
    099         */
    100        public boolean isInWater()
    101        {
    102            return this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(0.0D, -0.6000000238418579D, 0.0D), Material.water, this);
    103        }
    104
    105        /**
    106         * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
    107         * use this to react to sunlight and start to burn.
    108         */
    109        public void onLivingUpdate()
    110        {
    111            super.onLivingUpdate();
    112            this.field_70862_e = this.field_70861_d;
    113            this.field_70860_g = this.field_70859_f;
    114            this.field_70868_i = this.field_70867_h;
    115            this.lastTentacleAngle = this.tentacleAngle;
    116            this.field_70867_h += this.field_70864_bA;
    117
    118            if (this.field_70867_h > ((float)Math.PI * 2F))
    119            {
    120                this.field_70867_h -= ((float)Math.PI * 2F);
    121
    122                if (this.rand.nextInt(10) == 0)
    123                {
    124                    this.field_70864_bA = 1.0F / (this.rand.nextFloat() + 1.0F) * 0.2F;
    125                }
    126            }
    127
    128            if (this.isInWater())
    129            {
    130                float var1;
    131
    132                if (this.field_70867_h < (float)Math.PI)
    133                {
    134                    var1 = this.field_70867_h / (float)Math.PI;
    135                    this.tentacleAngle = MathHelper.sin(var1 * var1 * (float)Math.PI) * (float)Math.PI * 0.25F;
    136
    137                    if ((double)var1 > 0.75D)
    138                    {
    139                        this.randomMotionSpeed = 1.0F;
    140                        this.field_70871_bB = 1.0F;
    141                    }
    142                    else
    143                    {
    144                        this.field_70871_bB *= 0.8F;
    145                    }
    146                }
    147                else
    148                {
    149                    this.tentacleAngle = 0.0F;
    150                    this.randomMotionSpeed *= 0.9F;
    151                    this.field_70871_bB *= 0.99F;
    152                }
    153
    154                if (!this.worldObj.isRemote)
    155                {
    156                    this.motionX = (double)(this.randomMotionVecX * this.randomMotionSpeed);
    157                    this.motionY = (double)(this.randomMotionVecY * this.randomMotionSpeed);
    158                    this.motionZ = (double)(this.randomMotionVecZ * this.randomMotionSpeed);
    159                }
    160
    161                var1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
    162                this.renderYawOffset += (-((float)Math.atan2(this.motionX, this.motionZ)) * 180.0F / (float)Math.PI - this.renderYawOffset) * 0.1F;
    163                this.rotationYaw = this.renderYawOffset;
    164                this.field_70859_f += (float)Math.PI * this.field_70871_bB * 1.5F;
    165                this.field_70861_d += (-((float)Math.atan2((double)var1, this.motionY)) * 180.0F / (float)Math.PI - this.field_70861_d) * 0.1F;
    166            }
    167            else
    168            {
    169                this.tentacleAngle = MathHelper.abs(MathHelper.sin(this.field_70867_h)) * (float)Math.PI * 0.25F;
    170
    171                if (!this.worldObj.isRemote)
    172                {
    173                    this.motionX = 0.0D;
    174                    this.motionY -= 0.08D;
    175                    this.motionY *= 0.9800000190734863D;
    176                    this.motionZ = 0.0D;
    177                }
    178
    179                this.field_70861_d = (float)((double)this.field_70861_d + (double)(-90.0F - this.field_70861_d) * 0.02D);
    180            }
    181        }
    182
    183        /**
    184         * Moves the entity based on the specified heading.  Args: strafe, forward
    185         */
    186        public void moveEntityWithHeading(float par1, float par2)
    187        {
    188            this.moveEntity(this.motionX, this.motionY, this.motionZ);
    189        }
    190
    191        protected void updateEntityActionState()
    192        {
    193            ++this.entityAge;
    194
    195            if (this.entityAge > 100)
    196            {
    197                this.randomMotionVecX = this.randomMotionVecY = this.randomMotionVecZ = 0.0F;
    198            }
    199            else if (this.rand.nextInt(50) == 0 || !this.inWater || this.randomMotionVecX == 0.0F && this.randomMotionVecY == 0.0F && this.randomMotionVecZ == 0.0F)
    200            {
    201                float var1 = this.rand.nextFloat() * (float)Math.PI * 2.0F;
    202                this.randomMotionVecX = MathHelper.cos(var1) * 0.2F;
    203                this.randomMotionVecY = -0.1F + this.rand.nextFloat() * 0.2F;
    204                this.randomMotionVecZ = MathHelper.sin(var1) * 0.2F;
    205            }
    206
    207            this.despawnEntity();
    208        }
    209
    210        /**
    211         * Checks if the entity's current position is a valid location to spawn this entity.
    212         */
    213        public boolean getCanSpawnHere()
    214        {
    215            return this.posY > 45.0D && this.posY < 63.0D && super.getCanSpawnHere();
    216        }
    217    }