    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 i = MathHelper.floor_double(this.entity.boundingBox.minY + 0.5D);
    056            double d0 = this.posX - this.entity.posX;
    057            double d1 = this.posZ - this.entity.posZ;
    058            double d2 = this.posY - (double)i;
    059            double d3 = d0 * d0 + d2 * d2 + d1 * d1;
    060
    061            if (d3 >= 2.500000277905201E-7D)
    062            {
    063                float f = (float)(Math.atan2(d1, d0) * 180.0D / Math.PI) - 90.0F;
    064                this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, f, 30.0F);
    065                this.entity.setAIMoveSpeed(this.speed * this.entity.getSpeedModifier());
    066
    067                if (d2 > 0.0D && d0 * d0 + d1 * d1 < 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 f3 = MathHelper.wrapAngleTo180_float(par2 - par1);
    081
    082        if (f3 > par3)
    083        {
    084            f3 = par3;
    085        }
    086
    087        if (f3 < -par3)
    088        {
    089            f3 = -par3;
    090        }
    091
    092        return par1 + f3;
    093    }
    094}