EntityMoveHelper .java

net.minecraft.entity.ai.EntityMoveHelper (class): members: onUpdateMoveHelper, isUpdating, limitAngle, setMoveTo, getSpeed, entity, speed, posZ, posX.

net.minecraft.entity.aiclass122 linescommon2.9 KB

API Surface (8)

boolean isUpdating()
double getSpeed()
void setMoveTo(double x, double y, double z, double speedIn)
void onUpdateMoveHelper()
float limitAngle(float p_75639_1_, float p_75639_2_, float p_75639_3_)
double getX()
double getY()
double getZ()

Fields & Constants (6)

entity
posX
posY
posZ
speed
update

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EntityMoveHelper.java122 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import net.minecraft.entity.EntityLiving;
4
import net.minecraft.entity.SharedMonsterAttributes;
5
import net.minecraft.util.MathHelper;
6
7
public class EntityMoveHelper
8
{
9
    /** The EntityLiving that is being moved */
10
    protected EntityLiving entity;
11
    protected double posX;
12
    protected double posY;
13
    protected double posZ;
14
15
    /** The speed at which the entity should move */
16
    protected double speed;
17
    protected boolean update;
18
19
    public EntityMoveHelper(EntityLiving entitylivingIn)
20
    {
21
        this.entity = entitylivingIn;
22
        this.posX = entitylivingIn.posX;
23
        this.posY = entitylivingIn.posY;
24
        this.posZ = entitylivingIn.posZ;
25
    }
26
27
    public boolean isUpdating()
28
    {
29
        return this.update;
30
    }
31
32
    public double getSpeed()
33
    {
34
        return this.speed;
35
    }
36
37
    /**
38
     * Sets the speed and location to move to
39
     */
40
    public void setMoveTo(double x, double y, double z, double speedIn)
41
    {
42
        this.posX = x;
43
        this.posY = y;
44
        this.posZ = z;
45
        this.speed = speedIn;
46
        this.update = true;
47
    }
48
49
    public void onUpdateMoveHelper()
50
    {
51
        this.entity.setMoveForward(0.0F);
52
53
        if (this.update)
54
        {
55
            this.update = false;
56
            int i = MathHelper.floor_double(this.entity.getEntityBoundingBox().minY + 0.5D);
57
            double d0 = this.posX - this.entity.posX;
58
            double d1 = this.posZ - this.entity.posZ;
59
            double d2 = this.posY - (double)i;
60
            double d3 = d0 * d0 + d2 * d2 + d1 * d1;
61
62
            if (d3 >= 2.500000277905201E-7D)
63
            {
64
                float f = (float)(MathHelper.atan2(d1, d0) * 180.0D / Math.PI) - 90.0F;
65
                this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, f, 30.0F);
66
                this.entity.setAIMoveSpeed((float)(this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue()));
67
68
                if (d2 > 0.0D && d0 * d0 + d1 * d1 < 1.0D)
69
                {
70
                    this.entity.getJumpHelper().setJumping();
71
                }
72
            }
73
        }
74
    }
75
76
    /**
77
     * Limits the given angle to a upper and lower limit.
78
     */
79
    protected float limitAngle(float p_75639_1_, float p_75639_2_, float p_75639_3_)
80
    {
81
        float f = MathHelper.wrapAngleTo180_float(p_75639_2_ - p_75639_1_);
82
83
        if (f > p_75639_3_)
84
        {
85
            f = p_75639_3_;
86
        }
87
88
        if (f < -p_75639_3_)
89
        {
90
            f = -p_75639_3_;
91
        }
92
93
        float f1 = p_75639_1_ + f;
94
95
        if (f1 < 0.0F)
96
        {
97
            f1 += 360.0F;
98
        }
99
        else if (f1 > 360.0F)
100
        {
101
            f1 -= 360.0F;
102
        }
103
104
        return f1;
105
    }
106
107
    public double getX()
108
    {
109
        return this.posX;
110
    }
111
112
    public double getY()
113
    {
114
        return this.posY;
115
    }
116
117
    public double getZ()
118
    {
119
        return this.posZ;
120
    }
121
}
122

Deobfuscated MCP 1.8.9 source of EntityMoveHelper from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/ai/EntityMoveHelper.java), stored verbatim.