Path .java

net.minecraft.pathfinding.Path (class): members: changeDistance, isPathEmpty, pathPoints, clearPath, addPoint, dequeue, count. strings: "OW KNOWS!".

net.minecraft.pathfindingclass176 linescommon4.1 KB

API Surface (5)

PathPoint addPoint(PathPoint point)
void clearPath()
PathPoint dequeue()
void changeDistance(PathPoint p_75850_1_, float p_75850_2_)
boolean isPathEmpty()

Fields & Constants (2)

pathPoints
count

String literals (1)

"OW KNOWS!"

Code Graph: Dependencies (1)

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

Full Source

Path.java176 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.pathfinding;
2
3
public class Path
4
{
5
    /** Contains the points in this path */
6
    private PathPoint[] pathPoints = new PathPoint[1024];
7
8
    /** The number of points in this path */
9
    private int count;
10
11
    /**
12
     * Adds a point to the path
13
     */
14
    public PathPoint addPoint(PathPoint point)
15
    {
16
        if (point.index >= 0)
17
        {
18
            throw new IllegalStateException("OW KNOWS!");
19
        }
20
        else
21
        {
22
            if (this.count == this.pathPoints.length)
23
            {
24
                PathPoint[] apathpoint = new PathPoint[this.count << 1];
25
                System.arraycopy(this.pathPoints, 0, apathpoint, 0, this.count);
26
                this.pathPoints = apathpoint;
27
            }
28
29
            this.pathPoints[this.count] = point;
30
            point.index = this.count;
31
            this.sortBack(this.count++);
32
            return point;
33
        }
34
    }
35
36
    /**
37
     * Clears the path
38
     */
39
    public void clearPath()
40
    {
41
        this.count = 0;
42
    }
43
44
    /**
45
     * Returns and removes the first point in the path
46
     */
47
    public PathPoint dequeue()
48
    {
49
        PathPoint pathpoint = this.pathPoints[0];
50
        this.pathPoints[0] = this.pathPoints[--this.count];
51
        this.pathPoints[this.count] = null;
52
53
        if (this.count > 0)
54
        {
55
            this.sortForward(0);
56
        }
57
58
        pathpoint.index = -1;
59
        return pathpoint;
60
    }
61
62
    /**
63
     * Changes the provided point's distance to target
64
     */
65
    public void changeDistance(PathPoint p_75850_1_, float p_75850_2_)
66
    {
67
        float f = p_75850_1_.distanceToTarget;
68
        p_75850_1_.distanceToTarget = p_75850_2_;
69
70
        if (p_75850_2_ < f)
71
        {
72
            this.sortBack(p_75850_1_.index);
73
        }
74
        else
75
        {
76
            this.sortForward(p_75850_1_.index);
77
        }
78
    }
79
80
    /**
81
     * Sorts a point to the left
82
     */
83
    private void sortBack(int p_75847_1_)
84
    {
85
        PathPoint pathpoint = this.pathPoints[p_75847_1_];
86
        int i;
87
88
        for (float f = pathpoint.distanceToTarget; p_75847_1_ > 0; p_75847_1_ = i)
89
        {
90
            i = p_75847_1_ - 1 >> 1;
91
            PathPoint pathpoint1 = this.pathPoints[i];
92
93
            if (f >= pathpoint1.distanceToTarget)
94
            {
95
                break;
96
            }
97
98
            this.pathPoints[p_75847_1_] = pathpoint1;
99
            pathpoint1.index = p_75847_1_;
100
        }
101
102
        this.pathPoints[p_75847_1_] = pathpoint;
103
        pathpoint.index = p_75847_1_;
104
    }
105
106
    /**
107
     * Sorts a point to the right
108
     */
109
    private void sortForward(int p_75846_1_)
110
    {
111
        PathPoint pathpoint = this.pathPoints[p_75846_1_];
112
        float f = pathpoint.distanceToTarget;
113
114
        while (true)
115
        {
116
            int i = 1 + (p_75846_1_ << 1);
117
            int j = i + 1;
118
119
            if (i >= this.count)
120
            {
121
                break;
122
            }
123
124
            PathPoint pathpoint1 = this.pathPoints[i];
125
            float f1 = pathpoint1.distanceToTarget;
126
            PathPoint pathpoint2;
127
            float f2;
128
129
            if (j >= this.count)
130
            {
131
                pathpoint2 = null;
132
                f2 = Float.POSITIVE_INFINITY;
133
            }
134
            else
135
            {
136
                pathpoint2 = this.pathPoints[j];
137
                f2 = pathpoint2.distanceToTarget;
138
            }
139
140
            if (f1 < f2)
141
            {
142
                if (f1 >= f)
143
                {
144
                    break;
145
                }
146
147
                this.pathPoints[p_75846_1_] = pathpoint1;
148
                pathpoint1.index = p_75846_1_;
149
                p_75846_1_ = i;
150
            }
151
            else
152
            {
153
                if (f2 >= f)
154
                {
155
                    break;
156
                }
157
158
                this.pathPoints[p_75846_1_] = pathpoint2;
159
                pathpoint2.index = p_75846_1_;
160
                p_75846_1_ = j;
161
            }
162
        }
163
164
        this.pathPoints[p_75846_1_] = pathpoint;
165
        pathpoint.index = p_75846_1_;
166
    }
167
168
    /**
169
     * Returns true if this path contains no points
170
     */
171
    public boolean isPathEmpty()
172
    {
173
        return this.count == 0;
174
    }
175
}
176

Deobfuscated MCP 1.8.9 source of Path from Marcelektro/MavenMCP-1.8.9 (net/minecraft/pathfinding/Path.java), stored verbatim.