Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package net.minecraft.server;
2
3public class Pathfinder {
4
5 private IBlockAccess a;
6 private Path b = new Path();
7 private EntityList c = new EntityList();
8 private PathPoint[] d = new PathPoint[32];
9
10 public Pathfinder(IBlockAccess iblockaccess) {
11 this.a = iblockaccess;
12 }
13
14 public PathEntity a(Entity entity, Entity entity1, float f) {
15 return this.a(entity, entity1.locX, entity1.boundingBox.b, entity1.locZ, f);
16 }
17
18 public PathEntity a(Entity entity, int i, int j, int k, float f) {
19 return this.a(entity, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), f);
20 }
21
22 private PathEntity a(Entity entity, double d0, double d1, double d2, float f) {
23 this.b.a();
24 this.c.a();
25 PathPoint pathpoint = this.a(MathHelper.floor(entity.boundingBox.a), MathHelper.floor(entity.boundingBox.b), MathHelper.floor(entity.boundingBox.c));
26 PathPoint pathpoint1 = this.a(MathHelper.floor(d0 - (double) (entity.length / 2.0F)), MathHelper.floor(d1), MathHelper.floor(d2 - (double) (entity.length / 2.0F)));
27 PathPoint pathpoint2 = new PathPoint(MathHelper.d(entity.length + 1.0F), MathHelper.d(entity.width + 1.0F), MathHelper.d(entity.length + 1.0F));
28 PathEntity pathentity = this.a(entity, pathpoint, pathpoint1, pathpoint2, f);
29
30 return pathentity;
31 }
32
33 private PathEntity a(Entity entity, PathPoint pathpoint, PathPoint pathpoint1, PathPoint pathpoint2, float f) {
34 pathpoint.e = 0.0F;
35 pathpoint.f = pathpoint.a(pathpoint1);
36 pathpoint.g = pathpoint.f;
37 this.b.a();
38 this.b.a(pathpoint);
39 PathPoint pathpoint3 = pathpoint;
40
41 while (!this.b.c()) {
42 PathPoint pathpoint4 = this.b.b();
43
44 if (pathpoint4.equals(pathpoint1)) {
45 return this.a(pathpoint, pathpoint1);
46 }
47
48 if (pathpoint4.a(pathpoint1) < pathpoint3.a(pathpoint1)) {
49 pathpoint3 = pathpoint4;
50 }
51
52 pathpoint4.i = true;
53 int i = this.b(entity, pathpoint4, pathpoint2, pathpoint1, f);
54
55 for (int j = 0; j < i; ++j) {
56 PathPoint pathpoint5 = this.d[j];
57 float f1 = pathpoint4.e + pathpoint4.a(pathpoint5);
58
59 if (!pathpoint5.a() || f1 < pathpoint5.e) {
60 pathpoint5.h = pathpoint4;
61 pathpoint5.e = f1;
62 pathpoint5.f = pathpoint5.a(pathpoint1);
63 if (pathpoint5.a()) {
64 this.b.a(pathpoint5, pathpoint5.e + pathpoint5.f);
65 } else {
66 pathpoint5.g = pathpoint5.e + pathpoint5.f;
67 this.b.a(pathpoint5);
68 }
69 }
70 }
71 }
72
73 if (pathpoint3 == pathpoint) {
74 return null;
75 } else {
76 return this.a(pathpoint, pathpoint3);
77 }
78 }
79
80 private int b(Entity entity, PathPoint pathpoint, PathPoint pathpoint1, PathPoint pathpoint2, float f) {
81 int i = 0;
82 byte b0 = 0;
83
84 if (this.a(entity, pathpoint.a, pathpoint.b + 1, pathpoint.c, pathpoint1) == 1) {
85 b0 = 1;
86 }
87
88 PathPoint pathpoint3 = this.a(entity, pathpoint.a, pathpoint.b, pathpoint.c + 1, pathpoint1, b0);
89 PathPoint pathpoint4 = this.a(entity, pathpoint.a - 1, pathpoint.b, pathpoint.c, pathpoint1, b0);
90 PathPoint pathpoint5 = this.a(entity, pathpoint.a + 1, pathpoint.b, pathpoint.c, pathpoint1, b0);
91 PathPoint pathpoint6 = this.a(entity, pathpoint.a, pathpoint.b, pathpoint.c - 1, pathpoint1, b0);
92
93 if (pathpoint3 != null && !pathpoint3.i && pathpoint3.a(pathpoint2) < f) {
94 this.d[i++] = pathpoint3;
95 }
96
97 if (pathpoint4 != null && !pathpoint4.i && pathpoint4.a(pathpoint2) < f) {
98 this.d[i++] = pathpoint4;
99 }
100
101 if (pathpoint5 != null && !pathpoint5.i && pathpoint5.a(pathpoint2) < f) {
102 this.d[i++] = pathpoint5;
103 }
104
105 if (pathpoint6 != null && !pathpoint6.i && pathpoint6.a(pathpoint2) < f) {
106 this.d[i++] = pathpoint6;
107 }
108
109 return i;
110 }
111
112 private PathPoint a(Entity entity, int i, int j, int k, PathPoint pathpoint, int l) {
113 PathPoint pathpoint1 = null;
114
115 if (this.a(entity, i, j, k, pathpoint) == 1) {
116 pathpoint1 = this.a(i, j, k);
117 }
118
119 if (pathpoint1 == null && l > 0 && this.a(entity, i, j + l, k, pathpoint) == 1) {
120 pathpoint1 = this.a(i, j + l, k);
121 j += l;
122 }
123
124 if (pathpoint1 != null) {
125 int i1 = 0;
126 int j1 = 0;
127
128 while (j > 0 && (j1 = this.a(entity, i, j - 1, k, pathpoint)) == 1) {
129 ++i1;
130 if (i1 >= 4) {
131 return null;
132 }
133
134 --j;
135 if (j > 0) {
136 pathpoint1 = this.a(i, j, k);
137 }
138 }
139
140 if (j1 == -2) {
141 return null;
142 }
143 }
144
145 return pathpoint1;
146 }
147
148 private final PathPoint a(int i, int j, int k) {
149 int l = PathPoint.a(i, j, k);
150 PathPoint pathpoint = (PathPoint) this.c.a(l);
151
152 if (pathpoint == null) {
153 pathpoint = new PathPoint(i, j, k);
154 this.c.a(l, pathpoint);
155 }
156
157 return pathpoint;
158 }
159
160 private int a(Entity entity, int i, int j, int k, PathPoint pathpoint) {
161 for (int l = i; l < i + pathpoint.a; ++l) {
162 for (int i1 = j; i1 < j + pathpoint.b; ++i1) {
163 for (int j1 = k; j1 < k + pathpoint.c; ++j1) {
164 int k1 = this.a.getTypeId(l, i1, j1);
165
166 if (k1 > 0) {
167 if (k1 != Block.IRON_DOOR_BLOCK.id && k1 != Block.WOODEN_DOOR.id) {
168 Material material = Block.byId[k1].material;
169
170 if (material.isSolid()) {
171 return 0;
172 }
173
174 if (material == Material.WATER) {
175 return -1;
176 }
177
178 if (material == Material.LAVA) {
179 return -2;
180 }
181 } else {
182 int l1 = this.a.getData(l, i1, j1);
183
184 if (!BlockDoor.e(l1)) {
185 return 0;
186 }
187 }
188 }
189 }
190 }
191 }
192
193 return 1;
194 }
195
196 private PathEntity a(PathPoint pathpoint, PathPoint pathpoint1) {
197 int i = 1;
198
199 PathPoint pathpoint2;
200
201 for (pathpoint2 = pathpoint1; pathpoint2.h != null; pathpoint2 = pathpoint2.h) {
202 ++i;
203 }
204
205 PathPoint[] apathpoint = new PathPoint[i];
206
207 pathpoint2 = pathpoint1;
208 --i;
209
210 for (apathpoint[i] = pathpoint1; pathpoint2.h != null; apathpoint[i] = pathpoint2) {
211 pathpoint2 = pathpoint2.h;
212 --i;
213 }
214
215 return new PathEntity(apathpoint);
216 }
217}