    001package net.minecraft.entity.ai;
    002
    003import net.minecraft.entity.EntityLiving;
    004import net.minecraft.util.MathHelper;
    005
    006public class EntityMoveHelper
    007{
    008    /** The EntityLiving that is being moved */
    009    private EntityLiving entity;
    010    private double posX;
    011    private double posY;
    012    private double posZ;
    013
    014    /** The speed at which the entity should move */
    015    private float speed;
    016    private boolean update = false;
    017
    018    public EntityMoveHelper(EntityLiving par1EntityLiving)
    019    {
    020        this.entity = par1EntityLiving;
    021        this.posX = par1EntityLiving.posX;
    022        this.posY = par1EntityLiving.posY;
    023        this.posZ = par1EntityLiving.posZ;
    024    }
    025
    026    public boolean isUpdating()
    027    {
    028        return this.update;
    029    }
    030
    031    public float getSpeed()
    032    {
    033        return this.speed;
    034    }
    035
    036    /**
    037     * Sets the speed and location to move to
    038     */
    039    public void setMoveTo(double par1, double par3, double par5, float par7)
    040    {
    041        this.posX = par1;
    042        this.posY = par3;
    043        this.posZ = par5;
    044        this.speed = par7;
    045        this.update = true;
    046    }
    047
    048    public void onUpdateMoveHelper()
    049    {
    050        this.entity.setMoveForward(0.0F);
    051
    052        if (this.update)
    053        {
    054            this.update = false;
    055            int var1 = MathHelper.floor_double(this.entity.boundingBox.minY + 0.5D);
    056            double var2 = this.posX - this.entity.posX;
    057            double var4 = this.posZ - this.entity.posZ;
    058            double var6 = this.posY - (double)var1;
    059            double var8 = var2 * var2 + var6 * var6 + var4 * var4;
    060
    061            if (var8 >= 2.500000277905201E-7D)
    062            {
    063                float var10 = (float)(Math.atan2(var4, var2) * 180.0D / Math.PI) - 90.0F;
    064                this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, var10, 30.0F);
    065                this.entity.setAIMoveSpeed(this.speed * this.entity.getSpeedModifier());
    066
    067                if (var6 > 0.0D && var2 * var2 + var4 * var4 < 1.0D)
    068                {
    069                    this.entity.getJumpHelper().setJumping();
    070                }
    071            }
    072        }
    073    }
    074
    075    /**
    076     * Limits the given angle to a upper and lower limit.
    077     */
    078    private float limitAngle(float par1, float par2, float par3)
    079    {
    080        float var4 = MathHelper.wrapAngleTo180_float(par2 - par1);
    081
    082        if (var4 > par3)
    083        {
    084            var4 = par3;
    085        }
    086
    087        if (var4 < -par3)
    088        {
    089            var4 = -par3;
    090        }
    091
    092        return par1 + var4;
    093    }
    094}