PathNavigateGround .java

net.minecraft.pathfinding.PathNavigateGround (class): members: shouldAvoidSun, setAvoidSun, getAvoidsWater, setAvoidsWater, getEnterDoors, nodeProcessor.

net.minecraft.pathfindingclass297 linescommonextends PathNavigate9.3 KB

API Surface (13)

PathFinder getPathFinder()
boolean canNavigate()
Vec3 getEntityPosition()
void removeSunnyPath()
boolean isDirectPathBetweenPoints(Vec3 posVec31, Vec3 posVec32, int sizeX, int sizeY, int sizeZ)
void setAvoidsWater(boolean avoidsWater)
boolean getAvoidsWater()
void setBreakDoors(boolean canBreakDoors)
void setEnterDoors(boolean par1)
boolean getEnterDoors()
void setCanSwim(boolean canSwim)
boolean getCanSwim()
void setAvoidSun(boolean par1)

Fields & Constants (2)

nodeProcessor
shouldAvoidSun

Full Source

PathNavigateGround.java297 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.pathfinding;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.block.material.Material;
5
import net.minecraft.entity.EntityLiving;
6
import net.minecraft.entity.monster.EntityZombie;
7
import net.minecraft.entity.passive.EntityChicken;
8
import net.minecraft.init.Blocks;
9
import net.minecraft.util.BlockPos;
10
import net.minecraft.util.MathHelper;
11
import net.minecraft.util.Vec3;
12
import net.minecraft.world.World;
13
import net.minecraft.world.pathfinder.WalkNodeProcessor;
14
15
public class PathNavigateGround extends PathNavigate
16
{
17
    protected WalkNodeProcessor nodeProcessor;
18
    private boolean shouldAvoidSun;
19
20
    public PathNavigateGround(EntityLiving entitylivingIn, World worldIn)
21
    {
22
        super(entitylivingIn, worldIn);
23
    }
24
25
    protected PathFinder getPathFinder()
26
    {
27
        this.nodeProcessor = new WalkNodeProcessor();
28
        this.nodeProcessor.setEnterDoors(true);
29
        return new PathFinder(this.nodeProcessor);
30
    }
31
32
    /**
33
     * If on ground or swimming and can swim
34
     */
35
    protected boolean canNavigate()
36
    {
37
        return this.theEntity.onGround || this.getCanSwim() && this.isInLiquid() || this.theEntity.isRiding() && this.theEntity instanceof EntityZombie && this.theEntity.ridingEntity instanceof EntityChicken;
38
    }
39
40
    protected Vec3 getEntityPosition()
41
    {
42
        return new Vec3(this.theEntity.posX, (double)this.getPathablePosY(), this.theEntity.posZ);
43
    }
44
45
    /**
46
     * Gets the safe pathing Y position for the entity depending on if it can path swim or not
47
     */
48
    private int getPathablePosY()
49
    {
50
        if (this.theEntity.isInWater() && this.getCanSwim())
51
        {
52
            int i = (int)this.theEntity.getEntityBoundingBox().minY;
53
            Block block = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.theEntity.posX), i, MathHelper.floor_double(this.theEntity.posZ))).getBlock();
54
            int j = 0;
55
56
            while (block == Blocks.flowing_water || block == Blocks.water)
57
            {
58
                ++i;
59
                block = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.theEntity.posX), i, MathHelper.floor_double(this.theEntity.posZ))).getBlock();
60
                ++j;
61
62
                if (j > 16)
63
                {
64
                    return (int)this.theEntity.getEntityBoundingBox().minY;
65
                }
66
            }
67
68
            return i;
69
        }
70
        else
71
        {
72
            return (int)(this.theEntity.getEntityBoundingBox().minY + 0.5D);
73
        }
74
    }
75
76
    /**
77
     * Trims path data from the end to the first sun covered block
78
     */
79
    protected void removeSunnyPath()
80
    {
81
        super.removeSunnyPath();
82
83
        if (this.shouldAvoidSun)
84
        {
85
            if (this.worldObj.canSeeSky(new BlockPos(MathHelper.floor_double(this.theEntity.posX), (int)(this.theEntity.getEntityBoundingBox().minY + 0.5D), MathHelper.floor_double(this.theEntity.posZ))))
86
            {
87
                return;
88
            }
89
90
            for (int i = 0; i < this.currentPath.getCurrentPathLength(); ++i)
91
            {
92
                PathPoint pathpoint = this.currentPath.getPathPointFromIndex(i);
93
94
                if (this.worldObj.canSeeSky(new BlockPos(pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord)))
95
                {
96
                    this.currentPath.setCurrentPathLength(i - 1);
97
                    return;
98
                }
99
            }
100
        }
101
    }
102
103
    /**
104
     * Returns true when an entity of specified size could safely walk in a straight line between the two points. Args:
105
     * pos1, pos2, entityXSize, entityYSize, entityZSize
106
     */
107
    protected boolean isDirectPathBetweenPoints(Vec3 posVec31, Vec3 posVec32, int sizeX, int sizeY, int sizeZ)
108
    {
109
        int i = MathHelper.floor_double(posVec31.xCoord);
110
        int j = MathHelper.floor_double(posVec31.zCoord);
111
        double d0 = posVec32.xCoord - posVec31.xCoord;
112
        double d1 = posVec32.zCoord - posVec31.zCoord;
113
        double d2 = d0 * d0 + d1 * d1;
114
115
        if (d2 < 1.0E-8D)
116
        {
117
            return false;
118
        }
119
        else
120
        {
121
            double d3 = 1.0D / Math.sqrt(d2);
122
            d0 = d0 * d3;
123
            d1 = d1 * d3;
124
            sizeX = sizeX + 2;
125
            sizeZ = sizeZ + 2;
126
127
            if (!this.isSafeToStandAt(i, (int)posVec31.yCoord, j, sizeX, sizeY, sizeZ, posVec31, d0, d1))
128
            {
129
                return false;
130
            }
131
            else
132
            {
133
                sizeX = sizeX - 2;
134
                sizeZ = sizeZ - 2;
135
                double d4 = 1.0D / Math.abs(d0);
136
                double d5 = 1.0D / Math.abs(d1);
137
                double d6 = (double)(i * 1) - posVec31.xCoord;
138
                double d7 = (double)(j * 1) - posVec31.zCoord;
139
140
                if (d0 >= 0.0D)
141
                {
142
                    ++d6;
143
                }
144
145
                if (d1 >= 0.0D)
146
                {
147
                    ++d7;
148
                }
149
150
                d6 = d6 / d0;
151
                d7 = d7 / d1;
152
                int k = d0 < 0.0D ? -1 : 1;
153
                int l = d1 < 0.0D ? -1 : 1;
154
                int i1 = MathHelper.floor_double(posVec32.xCoord);
155
                int j1 = MathHelper.floor_double(posVec32.zCoord);
156
                int k1 = i1 - i;
157
                int l1 = j1 - j;
158
159
                while (k1 * k > 0 || l1 * l > 0)
160
                {
161
                    if (d6 < d7)
162
                    {
163
                        d6 += d4;
164
                        i += k;
165
                        k1 = i1 - i;
166
                    }
167
                    else
168
                    {
169
                        d7 += d5;
170
                        j += l;
171
                        l1 = j1 - j;
172
                    }
173
174
                    if (!this.isSafeToStandAt(i, (int)posVec31.yCoord, j, sizeX, sizeY, sizeZ, posVec31, d0, d1))
175
                    {
176
                        return false;
177
                    }
178
                }
179
180
                return true;
181
            }
182
        }
183
    }
184
185
    /**
186
     * Returns true when an entity could stand at a position, including solid blocks under the entire entity.
187
     */
188
    private boolean isSafeToStandAt(int x, int y, int z, int sizeX, int sizeY, int sizeZ, Vec3 vec31, double p_179683_8_, double p_179683_10_)
189
    {
190
        int i = x - sizeX / 2;
191
        int j = z - sizeZ / 2;
192
193
        if (!this.isPositionClear(i, y, j, sizeX, sizeY, sizeZ, vec31, p_179683_8_, p_179683_10_))
194
        {
195
            return false;
196
        }
197
        else
198
        {
199
            for (int k = i; k < i + sizeX; ++k)
200
            {
201
                for (int l = j; l < j + sizeZ; ++l)
202
                {
203
                    double d0 = (double)k + 0.5D - vec31.xCoord;
204
                    double d1 = (double)l + 0.5D - vec31.zCoord;
205
206
                    if (d0 * p_179683_8_ + d1 * p_179683_10_ >= 0.0D)
207
                    {
208
                        Block block = this.worldObj.getBlockState(new BlockPos(k, y - 1, l)).getBlock();
209
                        Material material = block.getMaterial();
210
211
                        if (material == Material.air)
212
                        {
213
                            return false;
214
                        }
215
216
                        if (material == Material.water && !this.theEntity.isInWater())
217
                        {
218
                            return false;
219
                        }
220
221
                        if (material == Material.lava)
222
                        {
223
                            return false;
224
                        }
225
                    }
226
                }
227
            }
228
229
            return true;
230
        }
231
    }
232
233
    /**
234
     * Returns true if an entity does not collide with any solid blocks at the position.
235
     */
236
    private boolean isPositionClear(int p_179692_1_, int p_179692_2_, int p_179692_3_, int p_179692_4_, int p_179692_5_, int p_179692_6_, Vec3 p_179692_7_, double p_179692_8_, double p_179692_10_)
237
    {
238
        for (BlockPos blockpos : BlockPos.getAllInBox(new BlockPos(p_179692_1_, p_179692_2_, p_179692_3_), new BlockPos(p_179692_1_ + p_179692_4_ - 1, p_179692_2_ + p_179692_5_ - 1, p_179692_3_ + p_179692_6_ - 1)))
239
        {
240
            double d0 = (double)blockpos.getX() + 0.5D - p_179692_7_.xCoord;
241
            double d1 = (double)blockpos.getZ() + 0.5D - p_179692_7_.zCoord;
242
243
            if (d0 * p_179692_8_ + d1 * p_179692_10_ >= 0.0D)
244
            {
245
                Block block = this.worldObj.getBlockState(blockpos).getBlock();
246
247
                if (!block.isPassable(this.worldObj, blockpos))
248
                {
249
                    return false;
250
                }
251
            }
252
        }
253
254
        return true;
255
    }
256
257
    public void setAvoidsWater(boolean avoidsWater)
258
    {
259
        this.nodeProcessor.setAvoidsWater(avoidsWater);
260
    }
261
262
    public boolean getAvoidsWater()
263
    {
264
        return this.nodeProcessor.getAvoidsWater();
265
    }
266
267
    public void setBreakDoors(boolean canBreakDoors)
268
    {
269
        this.nodeProcessor.setBreakDoors(canBreakDoors);
270
    }
271
272
    public void setEnterDoors(boolean par1)
273
    {
274
        this.nodeProcessor.setEnterDoors(par1);
275
    }
276
277
    public boolean getEnterDoors()
278
    {
279
        return this.nodeProcessor.getEnterDoors();
280
    }
281
282
    public void setCanSwim(boolean canSwim)
283
    {
284
        this.nodeProcessor.setCanSwim(canSwim);
285
    }
286
287
    public boolean getCanSwim()
288
    {
289
        return this.nodeProcessor.getCanSwim();
290
    }
291
292
    public void setAvoidSun(boolean par1)
293
    {
294
        this.shouldAvoidSun = par1;
295
    }
296
}
297

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