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
|
package ihl;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
public class IHL3dPathFinder {
public double waypointX;
public double waypointY;
public double waypointZ;
public int lowestPointX;
public int lowestPointY;
public int lowestPointZ;
public double targetX;
public double targetY;
public double targetZ;
private Entity entity;
public IHL3dPathFinder(Entity entity1)
{
this.entity=entity1;
}
public boolean findPath(double x2, double y2, double z2)
{
if(this.isCourseTraversable(x2, y2, z2, this.entity.posX, this.entity.posY, this.entity.posZ))
{
this.waypointX=x2;
this.waypointY=y2;
this.waypointZ=z2;
return true;
}
else
{
return this.takeVector(x2, y2, z2);
}
}
private boolean isCourseTraversable(double toX, double toY, double toZ, double fromX, double fromY, double fromZ)
{
double var9 = toX - fromX;
double var11 = toY - fromY;
double var13 = toZ - fromZ;
double var7 = MathHelper.sqrt_double(var9 * var9 + var11 * var11 + var13 * var13);
var9 /= var7;
var11 /= var7;
var13 /= var7;
AxisAlignedBB var15 = this.entity.boundingBox.copy();
for (int var16 = 1; var16 < var7; ++var16)
{
var15.offset(var9, var11, var13);
if (!this.entity.worldObj.getCollidingBoundingBoxes(this.entity, var15).isEmpty())
{
return false;
}
}
return true;
}
private boolean takeVector(double toX, double toY, double toZ)
{
int x=Math.round((float)toX);
int y=Math.round((float)toY);
int z=Math.round((float)toZ);
int xyz[] = {0,0,1,0,0,-1,0,0};
Set<Long> list = new HashSet<Long>();
for(int thread=0;thread<=256;thread++)
{
if(this.isCourseTraversable(x+0.5D, y+0.5D, z+0.5D, this.entity.posX, this.entity.posY, this.entity.posZ))
{
this.waypointX=x+0.5D;
this.waypointY=y+0.5D;
this.waypointZ=z+0.5D;
return true;
}
Block block;
long number = new Long(x*256L*256L+y*256L+z);
list.add(number);
double lastDistanceSquared = this.entity.getDistanceSq(x, y, z);
boolean skip=false;
for(int i=0;i<=5;i++)
{
block = entity.worldObj.getBlock(x+xyz[i], y+xyz[i+1], z+xyz[i+2]);
number = new Long((x+xyz[i])*256L*256L+(y+xyz[i+1])*256L+z+xyz[i+2]);
if(block.isAir(entity.worldObj, x+xyz[i], y+xyz[i+1], z+xyz[i+2]) && !list.contains(number) && this.entity.getDistanceSq((double)x+xyz[i], (double)y+xyz[i+1], (double)z+xyz[i+2])<lastDistanceSquared)
{
x+=xyz[i];
y+=xyz[i+1];
z+=xyz[i+2];
skip=true;
break;
}
}
if(!skip)
{
for(int i=0;i<=5;i++)
{
block = entity.worldObj.getBlock(x+xyz[i], y+xyz[i+1], z+xyz[i+2]);
number = new Long((x+xyz[i])*256L*256L+(y+xyz[i+1])*256L+z+xyz[i+2]);
if(block.isAir(entity.worldObj, x+xyz[i], y+xyz[i+1], z+xyz[i+2]) && !list.contains(number))
{
x+=xyz[i];
y+=xyz[i+1];
z+=xyz[i+2];
break;
}
}
}
}
return false;
}
}
|