| 1 | package net.minecraft.pathfinding;
|
| 2 |
|
| 3 | import net.minecraft.entity.EntityLiving;
|
| 4 | import net.minecraft.util.MovingObjectPosition;
|
| 5 | import net.minecraft.util.Vec3;
|
| 6 | import net.minecraft.world.World;
|
| 7 | import net.minecraft.world.pathfinder.SwimNodeProcessor;
|
| 8 |
|
| 9 | public class PathNavigateSwimmer extends PathNavigate
|
| 10 | {
|
| 11 | public PathNavigateSwimmer(EntityLiving entitylivingIn, World worldIn)
|
| 12 | {
|
| 13 | super(entitylivingIn, worldIn);
|
| 14 | }
|
| 15 |
|
| 16 | protected PathFinder getPathFinder()
|
| 17 | {
|
| 18 | return new PathFinder(new SwimNodeProcessor());
|
| 19 | }
|
| 20 |
|
| 21 | /**
|
| 22 | * If on ground or swimming and can swim
|
| 23 | */
|
| 24 | protected boolean canNavigate()
|
| 25 | {
|
| 26 | return this.isInLiquid();
|
| 27 | }
|
| 28 |
|
| 29 | protected Vec3 getEntityPosition()
|
| 30 | {
|
| 31 | return new Vec3(this.theEntity.posX, this.theEntity.posY + (double)this.theEntity.height * 0.5D, this.theEntity.posZ);
|
| 32 | }
|
| 33 |
|
| 34 | protected void pathFollow()
|
| 35 | {
|
| 36 | Vec3 vec3 = this.getEntityPosition();
|
| 37 | float f = this.theEntity.width * this.theEntity.width;
|
| 38 | int i = 6;
|
| 39 |
|
| 40 | if (vec3.squareDistanceTo(this.currentPath.getVectorFromIndex(this.theEntity, this.currentPath.getCurrentPathIndex())) < (double)f)
|
| 41 | {
|
| 42 | this.currentPath.incrementPathIndex();
|
| 43 | }
|
| 44 |
|
| 45 | for (int j = Math.min(this.currentPath.getCurrentPathIndex() + i, this.currentPath.getCurrentPathLength() - 1); j > this.currentPath.getCurrentPathIndex(); --j)
|
| 46 | {
|
| 47 | Vec3 vec31 = this.currentPath.getVectorFromIndex(this.theEntity, j);
|
| 48 |
|
| 49 | if (vec31.squareDistanceTo(vec3) <= 36.0D && this.isDirectPathBetweenPoints(vec3, vec31, 0, 0, 0))
|
| 50 | {
|
| 51 | this.currentPath.setCurrentPathIndex(j);
|
| 52 | break;
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | this.checkForStuck(vec3);
|
| 57 | }
|
| 58 |
|
| 59 | /**
|
| 60 | * Trims path data from the end to the first sun covered block
|
| 61 | */
|
| 62 | protected void removeSunnyPath()
|
| 63 | {
|
| 64 | super.removeSunnyPath();
|
| 65 | }
|
| 66 |
|
| 67 | /**
|
| 68 | * Returns true when an entity of specified size could safely walk in a straight line between the two points. Args:
|
| 69 | * pos1, pos2, entityXSize, entityYSize, entityZSize
|
| 70 | */
|
| 71 | protected boolean isDirectPathBetweenPoints(Vec3 posVec31, Vec3 posVec32, int sizeX, int sizeY, int sizeZ)
|
| 72 | {
|
| 73 | MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(posVec31, new Vec3(posVec32.xCoord, posVec32.yCoord + (double)this.theEntity.height * 0.5D, posVec32.zCoord), false, true, false);
|
| 74 | return movingobjectposition == null || movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.MISS;
|
| 75 | }
|
| 76 | }
|
| 77 |
|