| 1 | package net.minecraft.pathfinding;
|
| 2 |
|
| 3 | import net.minecraft.entity.Entity;
|
| 4 | import net.minecraft.entity.EntityLiving;
|
| 5 | import net.minecraft.util.BlockPos;
|
| 6 | import net.minecraft.util.MathHelper;
|
| 7 | import net.minecraft.world.World;
|
| 8 |
|
| 9 | public class PathNavigateClimber extends PathNavigateGround
|
| 10 | {
|
| 11 | /** Current path navigation target */
|
| 12 | private BlockPos targetPosition;
|
| 13 |
|
| 14 | public PathNavigateClimber(EntityLiving entityLivingIn, World worldIn)
|
| 15 | {
|
| 16 | super(entityLivingIn, worldIn);
|
| 17 | }
|
| 18 |
|
| 19 | /**
|
| 20 | * Returns path to given BlockPos
|
| 21 | */
|
| 22 | public PathEntity getPathToPos(BlockPos pos)
|
| 23 | {
|
| 24 | this.targetPosition = pos;
|
| 25 | return super.getPathToPos(pos);
|
| 26 | }
|
| 27 |
|
| 28 | /**
|
| 29 | * Returns the path to the given EntityLiving. Args : entity
|
| 30 | */
|
| 31 | public PathEntity getPathToEntityLiving(Entity entityIn)
|
| 32 | {
|
| 33 | this.targetPosition = new BlockPos(entityIn);
|
| 34 | return super.getPathToEntityLiving(entityIn);
|
| 35 | }
|
| 36 |
|
| 37 | /**
|
| 38 | * Try to find and set a path to EntityLiving. Returns true if successful. Args : entity, speed
|
| 39 | */
|
| 40 | public boolean tryMoveToEntityLiving(Entity entityIn, double speedIn)
|
| 41 | {
|
| 42 | PathEntity pathentity = this.getPathToEntityLiving(entityIn);
|
| 43 |
|
| 44 | if (pathentity != null)
|
| 45 | {
|
| 46 | return this.setPath(pathentity, speedIn);
|
| 47 | }
|
| 48 | else
|
| 49 | {
|
| 50 | this.targetPosition = new BlockPos(entityIn);
|
| 51 | this.speed = speedIn;
|
| 52 | return true;
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | public void onUpdateNavigation()
|
| 57 | {
|
| 58 | if (!this.noPath())
|
| 59 | {
|
| 60 | super.onUpdateNavigation();
|
| 61 | }
|
| 62 | else
|
| 63 | {
|
| 64 | if (this.targetPosition != null)
|
| 65 | {
|
| 66 | double d0 = (double)(this.theEntity.width * this.theEntity.width);
|
| 67 |
|
| 68 | if (this.theEntity.getDistanceSqToCenter(this.targetPosition) >= d0 && (this.theEntity.posY <= (double)this.targetPosition.getY() || this.theEntity.getDistanceSqToCenter(new BlockPos(this.targetPosition.getX(), MathHelper.floor_double(this.theEntity.posY), this.targetPosition.getZ())) >= d0))
|
| 69 | {
|
| 70 | this.theEntity.getMoveHelper().setMoveTo((double)this.targetPosition.getX(), (double)this.targetPosition.getY(), (double)this.targetPosition.getZ(), this.speed);
|
| 71 | }
|
| 72 | else
|
| 73 | {
|
| 74 | this.targetPosition = null;
|
| 75 | }
|
| 76 | }
|
| 77 | }
|
| 78 | }
|
| 79 | }
|
| 80 |
|