001 package net.minecraft.entity.ai;
002
003 import net.minecraft.entity.EntityLiving;
004 import net.minecraft.util.MathHelper;
005
006 public 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 field_75643_f = 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 func_75640_a()
027 {
028 return this.field_75643_f;
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.field_75643_f = true;
046 }
047
048 public void onUpdateMoveHelper()
049 {
050 this.entity.setMoveForward(0.0F);
051
052 if (this.field_75643_f)
053 {
054 this.field_75643_f = 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.func_75639_a(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 private float func_75639_a(float par1, float par2, float par3)
076 {
077 float var4 = MathHelper.wrapAngleTo180_float(par2 - par1);
078
079 if (var4 > par3)
080 {
081 var4 = par3;
082 }
083
084 if (var4 < -par3)
085 {
086 var4 = -par3;
087 }
088
089 return par1 + var4;
090 }
091 }