/
PlayerNavigation.java
425 lines (379 loc) · 13.3 KB
/
PlayerNavigation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
package net.citizensnpcs.nms.v1_8_R3.util;
import java.util.List;
import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC;
import net.minecraft.server.v1_8_R3.AttributeInstance;
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.ChunkCache;
import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.EntityInsentient;
import net.minecraft.server.v1_8_R3.GenericAttributes;
import net.minecraft.server.v1_8_R3.Material;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.NavigationAbstract;
import net.minecraft.server.v1_8_R3.PathEntity;
import net.minecraft.server.v1_8_R3.PathPoint;
import net.minecraft.server.v1_8_R3.Pathfinder;
import net.minecraft.server.v1_8_R3.Vec3D;
import net.minecraft.server.v1_8_R3.World;
public class PlayerNavigation extends NavigationAbstract {
private final AttributeInstance a;
protected EntityHumanNPC b;
protected World c;
protected PathEntity d;
protected double e;
private int f;
private boolean fb;
private int g;
private Vec3D h = new Vec3D(0.0D, 0.0D, 0.0D);
private float i = 1.0F;
private final PlayerPathfinder j;
private final PlayerPathfinderNormal s;
public PlayerNavigation(EntityHumanNPC entityinsentient, World world) {
super(getDummyInsentient(entityinsentient, world), world);
this.b = entityinsentient;
this.c = world;
this.a = entityinsentient.getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
this.a.setValue(24);
this.s = new PlayerPathfinderNormal();
this.s.a(true);
this.j = new PlayerPathfinder(this.s);
// this.b.C().a(this);
}
@Override
protected Pathfinder a() {
return null;
}
@Override
public PathEntity a(BlockPosition paramBlockPosition) {
if (!b()) {
return null;
}
float f1 = i();
this.c.methodProfiler.a("pathfind");
BlockPosition localBlockPosition = new BlockPosition(this.b);
int k = (int) (f1 + 8.0F);
ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k),
localBlockPosition.a(k, k, k), 0);
PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramBlockPosition, f1);
this.c.methodProfiler.b();
return localPathEntity;
}
public void a(boolean paramBoolean) {
this.s.c(paramBoolean);
}
@Override
public void a(double paramDouble) {
this.e = paramDouble;
}
@Override
public boolean a(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4) {
PathEntity localPathEntity = a(MathHelper.floor(paramDouble1), (int) paramDouble2,
MathHelper.floor(paramDouble3));
return a(localPathEntity, paramDouble4);
}
@Override
public PathEntity a(Entity paramEntity) {
if (!b()) {
return null;
}
float f1 = i();
this.c.methodProfiler.a("pathfind");
BlockPosition localBlockPosition = new BlockPosition(this.b).up();
int k = (int) (f1 + 16.0F);
ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k),
localBlockPosition.a(k, k, k), 0);
PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramEntity, f1);
this.c.methodProfiler.b();
return localPathEntity;
}
@Override
public boolean a(Entity paramEntity, double paramDouble) {
PathEntity localPathEntity = a(paramEntity);
if (localPathEntity != null) {
return a(localPathEntity, paramDouble);
}
return false;
}
@Override
public void a(float paramFloat) {
this.i = paramFloat;
}
private boolean a(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6,
Vec3D paramVec3D, double paramDouble1, double paramDouble2) {
int i = paramInt1 - paramInt4 / 2;
int j = paramInt3 - paramInt6 / 2;
if (!b(i, paramInt2, j, paramInt4, paramInt5, paramInt6, paramVec3D, paramDouble1, paramDouble2)) {
return false;
}
for (int k = i; k < i + paramInt4; k++) {
for (int m = j; m < j + paramInt6; m++) {
double d1 = k + 0.5D - paramVec3D.a;
double d2 = m + 0.5D - paramVec3D.c;
if (d1 * paramDouble1 + d2 * paramDouble2 >= 0.0D) {
Block localBlock = this.c.getType(new BlockPosition(k, paramInt2 - 1, m)).getBlock();
Material localMaterial = localBlock.getMaterial();
if ((localMaterial == Material.AIR) || ((localMaterial == Material.WATER) && (!this.b.V())) || (localMaterial == Material.LAVA)) {
return false;
}
}
}
}
return true;
}
@Override
public boolean a(PathEntity paramPathEntity, double paramDouble) {
if (paramPathEntity == null) {
this.d = null;
return false;
}
if (!paramPathEntity.a(this.d)) {
this.d = paramPathEntity;
}
d();
if (this.d.d() == 0) {
return false;
}
this.e = paramDouble;
Vec3D localVec3D = c();
this.g = this.f;
this.h = localVec3D;
return true;
}
@Override
protected void a(Vec3D paramVec3D) {
if (this.f - this.g > 100) {
if (paramVec3D.distanceSquared(this.h) < 2.25D) {
n();
}
this.g = this.f;
this.h = paramVec3D;
}
}
@Override
protected boolean a(Vec3D paramVec3D1, Vec3D paramVec3D2, int paramInt1, int paramInt2, int paramInt3) {
int i = MathHelper.floor(paramVec3D1.a);
int j = MathHelper.floor(paramVec3D1.c);
double d1 = paramVec3D2.a - paramVec3D1.a;
double d2 = paramVec3D2.c - paramVec3D1.c;
double d3 = d1 * d1 + d2 * d2;
if (d3 < 1.0E-8D) {
return false;
}
double d4 = 1.0D / Math.sqrt(d3);
d1 *= d4;
d2 *= d4;
paramInt1 += 2;
paramInt3 += 2;
if (!a(i, (int) paramVec3D1.b, j, paramInt1, paramInt2, paramInt3, paramVec3D1, d1, d2)) {
return false;
}
paramInt1 -= 2;
paramInt3 -= 2;
double d5 = 1.0D / Math.abs(d1);
double d6 = 1.0D / Math.abs(d2);
double d7 = i * 1 - paramVec3D1.a;
double d8 = j * 1 - paramVec3D1.c;
if (d1 >= 0.0D) {
d7 += 1.0D;
}
if (d2 >= 0.0D) {
d8 += 1.0D;
}
d7 /= d1;
d8 /= d2;
int k = d1 < 0.0D ? -1 : 1;
int m = d2 < 0.0D ? -1 : 1;
int n = MathHelper.floor(paramVec3D2.a);
int i1 = MathHelper.floor(paramVec3D2.c);
int i2 = n - i;
int i3 = i1 - j;
while ((i2 * k > 0) || (i3 * m > 0)) {
if (d7 < d8) {
d7 += d5;
i += k;
i2 = n - i;
} else {
d8 += d6;
j += m;
i3 = i1 - j;
}
if (!a(i, (int) paramVec3D1.b, j, paramInt1, paramInt2, paramInt3, paramVec3D1, d1, d2)) {
return false;
}
}
return true;
}
@Override
protected boolean b() {
return (this.b.onGround) || ((h()) && (o())) || ((this.b.au()));
}
public void b(boolean paramBoolean) {
this.s.b(paramBoolean);
}
private boolean b(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6,
Vec3D paramVec3D, double paramDouble1, double paramDouble2) {
for (BlockPosition localBlockPosition : BlockPosition.a(new BlockPosition(paramInt1, paramInt2, paramInt3),
new BlockPosition(paramInt1 + paramInt4 - 1, paramInt2 + paramInt5 - 1, paramInt3 + paramInt6 - 1))) {
double d1 = (localBlockPosition.getX() + 0.5D) - paramVec3D.a;
double d2 = (localBlockPosition.getZ() + 0.5D) - paramVec3D.c;
if (d1 * paramDouble1 + d2 * paramDouble2 >= 0.0D) {
Block localBlock = this.c.getType(localBlockPosition).getBlock();
if (!localBlock.b(this.c, localBlockPosition)) {
return false;
}
}
}
return true;
}
@Override
protected Vec3D c() {
return new Vec3D(this.b.locX, p(), this.b.locZ);
}
public void c(boolean paramBoolean) {
this.s.a(paramBoolean);
}
@Override
protected void d() {
super.d();
if (this.fb) {
if (this.c.i(new BlockPosition(MathHelper.floor(this.b.locX), (int) (this.b.getBoundingBox().b + 0.5D),
MathHelper.floor(this.b.locZ)))) {
return;
}
for (int i = 0; i < this.d.d(); i++) {
PathPoint localPathPoint = this.d.a(i);
if (this.c.i(new BlockPosition(localPathPoint.a, localPathPoint.b, localPathPoint.c))) {
this.d.b(i - 1);
return;
}
}
}
}
public void d(boolean paramBoolean) {
this.s.d(paramBoolean);
}
public boolean e() {
return this.s.e();
}
public void e(boolean paramBoolean) {
this.fb = paramBoolean;
}
public boolean g() {
return this.s.b();
}
public boolean h() {
return this.s.d();
}
@Override
public float i() {
return (float) this.a.getValue();
}
@Override
public PathEntity j() {
return this.d;
}
@Override
public void k() {
this.f += 1;
if (m()) {
return;
}
if (b()) {
l();
} else if ((this.d != null) && (this.d.e() < this.d.d())) {
Vec3D localVec3D = c();
Vec3D localObject = this.d.a(this.b, this.d.e());
if ((localVec3D.b > localObject.b) && (!this.b.onGround)
&& (MathHelper.floor(localVec3D.a) == MathHelper.floor(localObject.a))
&& (MathHelper.floor(localVec3D.c) == MathHelper.floor(localObject.c))) {
this.d.c(this.d.e() + 1);
}
}
if (m()) {
return;
}
Vec3D localVec3D = this.d.a(this.b);
if (localVec3D == null) {
return;
}
Object localObject = new AxisAlignedBB(localVec3D.a, localVec3D.b, localVec3D.c, localVec3D.a, localVec3D.b,
localVec3D.c).grow(0.5D, 0.5D, 0.5D);
List<AxisAlignedBB> localList = this.c.getCubes(this.b, ((AxisAlignedBB) localObject).a(0.0D, -1.0D, 0.0D));
double d1 = -1.0D;
localObject = ((AxisAlignedBB) localObject).c(0.0D, 1.0D, 0.0D);
for (AxisAlignedBB localAxisAlignedBB : localList) {
d1 = localAxisAlignedBB.b((AxisAlignedBB) localObject, d1);
}
this.b.getControllerMove().a(localVec3D.a, localVec3D.b + d1, localVec3D.c, this.e);
}
@Override
protected void l() {
Vec3D localVec3D1 = c();
int k = this.d.d();
for (int m = this.d.e(); m < this.d.d(); m++) {
if (this.d.a(m).b != (int) localVec3D1.b) {
k = m;
break;
}
}
float f1 = this.b.width * this.b.width * this.i;
for (int n = this.d.e(); n < k; n++) {
Vec3D localVec3D2 = this.d.a(this.b, n);
if (localVec3D1.distanceSquared(localVec3D2) < f1) {
this.d.c(n + 1);
}
}
int n = MathHelper.f(this.b.width);
int i1 = (int) this.b.length + 1;
int i2 = n;
for (int i3 = k - 1; i3 >= this.d.e(); i3--) {
if (a(localVec3D1, this.d.a(this.b, i3), n, i1, i2)) {
this.d.c(i3);
break;
}
}
a(localVec3D1);
}
@Override
public boolean m() {
return (this.d == null) || (this.d.b());
}
@Override
public void n() {
this.d = null;
}
@Override
protected boolean o() {
return (this.b.V()) || (this.b.ab());
}
private int p() {
if ((!this.b.V()) || (!h())) {
return (int) (this.b.getBoundingBox().b + 0.5D);
}
int i = (int) this.b.getBoundingBox().b;
Block localBlock = this.c
.getType(new BlockPosition(MathHelper.floor(this.b.locX), i, MathHelper.floor(this.b.locZ))).getBlock();
int j = 0;
while ((localBlock == Blocks.FLOWING_WATER) || (localBlock == Blocks.WATER)) {
i++;
localBlock = this.c
.getType(new BlockPosition(MathHelper.floor(this.b.locX), i, MathHelper.floor(this.b.locZ)))
.getBlock();
j++;
if (j > 16) {
return (int) this.b.getBoundingBox().b;
}
}
return i;
}
public void setRange(float pathfindingRange) {
this.a.setValue(pathfindingRange);
}
private static EntityInsentient getDummyInsentient(EntityHumanNPC from, World world) {
return new EntityInsentient(world) {
};
}
}