    001    package net.minecraft.src;
    002
    003    public class EntityAIControlledByPlayer extends EntityAIBase
    004    {
    005        private final EntityLiving field_82640_a;
    006        private final float field_82638_b;
    007        private float field_82639_c = 0.0F;
    008        private boolean field_82636_d = false;
    009        private int field_82637_e = 0;
    010        private int field_82635_f = 0;
    011
    012        public EntityAIControlledByPlayer(EntityLiving par1EntityLiving, float par2)
    013        {
    014            this.field_82640_a = par1EntityLiving;
    015            this.field_82638_b = par2;
    016            this.setMutexBits(7);
    017        }
    018
    019        /**
    020         * Execute a one shot task or start executing a continuous task
    021         */
    022        public void startExecuting()
    023        {
    024            this.field_82639_c = 0.0F;
    025        }
    026
    027        /**
    028         * Resets the task
    029         */
    030        public void resetTask()
    031        {
    032            this.field_82636_d = false;
    033            this.field_82639_c = 0.0F;
    034        }
    035
    036        /**
    037         * Returns whether the EntityAIBase should begin execution.
    038         */
    039        public boolean shouldExecute()
    040        {
    041            return this.field_82640_a.isEntityAlive() && this.field_82640_a.riddenByEntity != null && this.field_82640_a.riddenByEntity instanceof EntityPlayer && (this.field_82636_d || this.field_82640_a.func_82171_bF());
    042        }
    043
    044        /**
    045         * Updates the task
    046         */
    047        public void updateTask()
    048        {
    049            EntityPlayer var1 = (EntityPlayer)this.field_82640_a.riddenByEntity;
    050            EntityCreature var2 = (EntityCreature)this.field_82640_a;
    051            float var3 = MathHelper.wrapAngleTo180_float(var1.rotationYaw - this.field_82640_a.rotationYaw) * 0.5F;
    052
    053            if (var3 > 5.0F)
    054            {
    055                var3 = 5.0F;
    056            }
    057
    058            if (var3 < -5.0F)
    059            {
    060                var3 = -5.0F;
    061            }
    062
    063            this.field_82640_a.rotationYaw = MathHelper.wrapAngleTo180_float(this.field_82640_a.rotationYaw + var3);
    064
    065            if (this.field_82639_c < this.field_82638_b)
    066            {
    067                this.field_82639_c += (this.field_82638_b - this.field_82639_c) * 0.01F;
    068            }
    069
    070            if (this.field_82639_c > this.field_82638_b)
    071            {
    072                this.field_82639_c = this.field_82638_b;
    073            }
    074
    075            int var4 = MathHelper.floor_double(this.field_82640_a.posX);
    076            int var5 = MathHelper.floor_double(this.field_82640_a.posY);
    077            int var6 = MathHelper.floor_double(this.field_82640_a.posZ);
    078            float var7 = this.field_82639_c;
    079
    080            if (this.field_82636_d)
    081            {
    082                if (this.field_82637_e++ > this.field_82635_f)
    083                {
    084                    this.field_82636_d = false;
    085                }
    086
    087                var7 += var7 * 1.15F * MathHelper.sin((float)this.field_82637_e / (float)this.field_82635_f * (float)Math.PI);
    088            }
    089
    090            float var8 = 0.91F;
    091
    092            if (this.field_82640_a.onGround)
    093            {
    094                var8 = 0.54600006F;
    095                int var9 = this.field_82640_a.worldObj.getBlockId(MathHelper.floor_float((float)var4), MathHelper.floor_float((float)var5) - 1, MathHelper.floor_float((float)var6));
    096
    097                if (var9 > 0)
    098                {
    099                    var8 = Block.blocksList[var9].slipperiness * 0.91F;
    100                }
    101            }
    102
    103            float var21 = 0.16277136F / (var8 * var8 * var8);
    104            float var10 = MathHelper.sin(var2.rotationYaw * (float)Math.PI / 180.0F);
    105            float var11 = MathHelper.cos(var2.rotationYaw * (float)Math.PI / 180.0F);
    106            float var12 = var2.getAIMoveSpeed() * var21;
    107            float var13 = Math.max(var7, 1.0F);
    108            var13 = var12 / var13;
    109            float var14 = var7 * var13;
    110            float var15 = -(var14 * var10);
    111            float var16 = var14 * var11;
    112
    113            if (MathHelper.abs(var15) > MathHelper.abs(var16))
    114            {
    115                if (var15 < 0.0F)
    116                {
    117                    var15 -= this.field_82640_a.width / 2.0F;
    118                }
    119
    120                if (var15 > 0.0F)
    121                {
    122                    var15 += this.field_82640_a.width / 2.0F;
    123                }
    124
    125                var16 = 0.0F;
    126            }
    127            else
    128            {
    129                var15 = 0.0F;
    130
    131                if (var16 < 0.0F)
    132                {
    133                    var16 -= this.field_82640_a.width / 2.0F;
    134                }
    135
    136                if (var16 > 0.0F)
    137                {
    138                    var16 += this.field_82640_a.width / 2.0F;
    139                }
    140            }
    141
    142            int var17 = MathHelper.floor_double(this.field_82640_a.posX + (double)var15);
    143            int var18 = MathHelper.floor_double(this.field_82640_a.posZ + (double)var16);
    144            PathPoint var19 = new PathPoint(MathHelper.floor_float(this.field_82640_a.width + 1.0F), MathHelper.floor_float(this.field_82640_a.height + var1.height + 1.0F), MathHelper.floor_float(this.field_82640_a.width + 1.0F));
    145
    146            if ((var4 != var17 || var6 != var18) && PathFinder.func_82565_a(this.field_82640_a, var17, var5, var18, var19, false, false, true) == 0 && PathFinder.func_82565_a(this.field_82640_a, var4, var5 + 1, var6, var19, false, false, true) == 1 && PathFinder.func_82565_a(this.field_82640_a, var17, var5 + 1, var18, var19, false, false, true) == 1)
    147            {
    148                var2.getJumpHelper().setJumping();
    149            }
    150
    151            if (!var1.capabilities.isCreativeMode && this.field_82639_c >= this.field_82638_b * 0.5F && this.field_82640_a.getRNG().nextFloat() < 0.006F && !this.field_82636_d)
    152            {
    153                ItemStack var20 = var1.getHeldItem();
    154
    155                if (var20 != null && var20.itemID == Item.field_82793_bR.shiftedIndex)
    156                {
    157                    var20.damageItem(1, var1);
    158
    159                    if (var20.stackSize == 0)
    160                    {
    161                        var1.inventory.mainInventory[var1.inventory.currentItem] = new ItemStack(Item.fishingRod);
    162                    }
    163                }
    164            }
    165
    166            this.field_82640_a.moveEntityWithHeading(0.0F, var7);
    167        }
    168
    169        public boolean func_82634_f()
    170        {
    171            return this.field_82636_d;
    172        }
    173
    174        public void func_82632_g()
    175        {
    176            this.field_82636_d = true;
    177            this.field_82637_e = 0;
    178            this.field_82635_f = this.field_82640_a.getRNG().nextInt(841) + 140;
    179        }
    180
    181        public boolean func_82633_h()
    182        {
    183            return !this.func_82634_f() && this.field_82639_c > this.field_82638_b * 0.3F;
    184        }
    185    }