| 1 | package net.minecraft.world.pathfinder;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.entity.Entity;
|
| 6 | import net.minecraft.pathfinding.PathPoint;
|
| 7 | import net.minecraft.util.BlockPos;
|
| 8 | import net.minecraft.util.EnumFacing;
|
| 9 | import net.minecraft.util.MathHelper;
|
| 10 | import net.minecraft.world.IBlockAccess;
|
| 11 |
|
| 12 | public class SwimNodeProcessor extends NodeProcessor
|
| 13 | {
|
| 14 | public void initProcessor(IBlockAccess iblockaccessIn, Entity entityIn)
|
| 15 | {
|
| 16 | super.initProcessor(iblockaccessIn, entityIn);
|
| 17 | }
|
| 18 |
|
| 19 | /**
|
| 20 | * This method is called when all nodes have been processed and PathEntity is created.
|
| 21 | * {@link net.minecraft.world.pathfinder.WalkNodeProcessor WalkNodeProcessor} uses this to change its field {@link
|
| 22 | * net.minecraft.world.pathfinder.WalkNodeProcessor#avoidsWater avoidsWater}
|
| 23 | */
|
| 24 | public void postProcess()
|
| 25 | {
|
| 26 | super.postProcess();
|
| 27 | }
|
| 28 |
|
| 29 | /**
|
| 30 | * Returns given entity's position as PathPoint
|
| 31 | */
|
| 32 | public PathPoint getPathPointTo(Entity entityIn)
|
| 33 | {
|
| 34 | return this.openPoint(MathHelper.floor_double(entityIn.getEntityBoundingBox().minX), MathHelper.floor_double(entityIn.getEntityBoundingBox().minY + 0.5D), MathHelper.floor_double(entityIn.getEntityBoundingBox().minZ));
|
| 35 | }
|
| 36 |
|
| 37 | /**
|
| 38 | * Returns PathPoint for given coordinates
|
| 39 | */
|
| 40 | public PathPoint getPathPointToCoords(Entity entityIn, double x, double y, double target)
|
| 41 | {
|
| 42 | return this.openPoint(MathHelper.floor_double(x - (double)(entityIn.width / 2.0F)), MathHelper.floor_double(y + 0.5D), MathHelper.floor_double(target - (double)(entityIn.width / 2.0F)));
|
| 43 | }
|
| 44 |
|
| 45 | public int findPathOptions(PathPoint[] pathOptions, Entity entityIn, PathPoint currentPoint, PathPoint targetPoint, float maxDistance)
|
| 46 | {
|
| 47 | int i = 0;
|
| 48 |
|
| 49 | for (EnumFacing enumfacing : EnumFacing.values())
|
| 50 | {
|
| 51 | PathPoint pathpoint = this.getSafePoint(entityIn, currentPoint.xCoord + enumfacing.getFrontOffsetX(), currentPoint.yCoord + enumfacing.getFrontOffsetY(), currentPoint.zCoord + enumfacing.getFrontOffsetZ());
|
| 52 |
|
| 53 | if (pathpoint != null && !pathpoint.visited && pathpoint.distanceTo(targetPoint) < maxDistance)
|
| 54 | {
|
| 55 | pathOptions[i++] = pathpoint;
|
| 56 | }
|
| 57 | }
|
| 58 |
|
| 59 | return i;
|
| 60 | }
|
| 61 |
|
| 62 | /**
|
| 63 | * Returns a point that the entity can safely move to
|
| 64 | */
|
| 65 | private PathPoint getSafePoint(Entity entityIn, int x, int y, int z)
|
| 66 | {
|
| 67 | int i = this.func_176186_b(entityIn, x, y, z);
|
| 68 | return i == -1 ? this.openPoint(x, y, z) : null;
|
| 69 | }
|
| 70 |
|
| 71 | private int func_176186_b(Entity entityIn, int x, int y, int z)
|
| 72 | {
|
| 73 | BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
| 74 |
|
| 75 | for (int i = x; i < x + this.entitySizeX; ++i)
|
| 76 | {
|
| 77 | for (int j = y; j < y + this.entitySizeY; ++j)
|
| 78 | {
|
| 79 | for (int k = z; k < z + this.entitySizeZ; ++k)
|
| 80 | {
|
| 81 | Block block = this.blockaccess.getBlockState(blockpos$mutableblockpos.set(i, j, k)).getBlock();
|
| 82 |
|
| 83 | if (block.getMaterial() != Material.water)
|
| 84 | {
|
| 85 | return 0;
|
| 86 | }
|
| 87 | }
|
| 88 | }
|
| 89 | }
|
| 90 |
|
| 91 | return -1;
|
| 92 | }
|
| 93 | }
|
| 94 |
|