@Override public boolean setPath(@Nullable final Path path, final double speed) { if (path == null) { this.currentPath = null; return false; } final int pathLength = path.getCurrentPathLength(); Path tempPath = null; if (pathLength > 0 && !(path.getPathPointFromIndex(0) instanceof PathPointExtended)) { // Fix vanilla PathPoints to be PathPointExtended @NotNull final PathPointExtended[] newPoints = new PathPointExtended[pathLength]; for (int i = 0; i < pathLength; ++i) { final PathPoint point = path.getPathPointFromIndex(i); newPoints[i] = new PathPointExtended(new BlockPos(point.x, point.y, point.z)); } tempPath = new Path(newPoints); final PathPointExtended finalPoint = newPoints[pathLength - 1]; destination = new BlockPos(finalPoint.x, finalPoint.y, finalPoint.z); } return super.setPath(tempPath == null ? path : tempPath, speed); }
@Override protected void pathFollow() { final int curNode = currentPath.getCurrentPathIndex(); final int curNodeNext = curNode + 1; if (curNodeNext < currentPath.getCurrentPathLength()) { final PathPointExtended pEx = (PathPointExtended) currentPath.getPathPointFromIndex(curNode); final PathPointExtended pExNext = (PathPointExtended) currentPath.getPathPointFromIndex(curNodeNext); // If current node is bottom of a ladder, then stay on this node until // the ourEntity reaches the bottom, otherwise they will try to head out early if (pEx.isOnLadder() && pEx.getLadderFacing() == EnumFacing.DOWN && !pExNext.isOnLadder()) { final Vec3d vec3 = getEntityPosition(); if ((vec3.y - (double) pEx.y) < 0.001) { this.currentPath.setCurrentPathIndex(curNodeNext); } this.checkForStuck(vec3); return; } } super.pathFollow(); }
private boolean addDoorCloseOnThePath(Path path) { for (int i = Math.max(path.getCurrentPathIndex() - 1, 0); i < Math.min(path.getCurrentPathIndex() + 2, path.getCurrentPathLength()); ++i) { PathPoint pathpoint = path.getPathPointFromIndex(i); if (this.theEntity.getDistanceSq(pathpoint.x + 0.5D, this.theEntity.posY, pathpoint.z + 0.5D) <= 1.5D) { BlockPos potentialDoorPos = new BlockPos(pathpoint.x, pathpoint.y, pathpoint.z); if (findDoor(potentialDoorPos)) { interactWithDoor(potentialDoorPos, true); return true; } else if (findDoor(potentialDoorPos.up())) { interactWithDoor(potentialDoorPos.up(), true); return true; } } } return false; }
protected Path trimPath(Path path) { if (path != null) { int index = path.getCurrentPathIndex(); PathPoint pathpoint = path.getPathPointFromIndex(index); if (npc.getBlockPathWeight(new BlockPos(pathpoint.x, pathpoint.y, pathpoint.z)) >= 0) { for (int i = index + 1; i < path.getCurrentPathLength(); i++) { pathpoint = path.getPathPointFromIndex(i); if (npc.getBlockPathWeight(new BlockPos(pathpoint.x, pathpoint.y, pathpoint.z)) < 0) { path.setCurrentPathLength(i - 1); break; } } } else { Vec3d vec = RandomPositionGenerator.findRandomTargetBlockAwayFrom(npc, MIN_RANGE, MIN_RANGE, new Vec3d(npc.posX, npc.posY, npc.posZ)); if (vec != null) return npc.getNavigator().getPathToXYZ(vec.x, vec.y, vec.z); } } return path; } }
/** * Checks if the citizen is close enough to an existing fence gate. * * @param path the path through the fence. * @return true if the gate can be passed */ private boolean checkFenceGate(@NotNull final Path path) { final int maxLengthToCheck = Math.min(path.getCurrentPathIndex() + LENGTH_TO_CHECK, path.getCurrentPathLength()); for (int i = 0; i < maxLengthToCheck; ++i) { final PathPoint pathpoint = path.getPathPointFromIndex(i); for (int level = 0; level < HEIGHT_TO_CHECK; level++) { this.gatePosition = new BlockPos(pathpoint.x, pathpoint.y + level, pathpoint.z); if (this.theEntity.getDistanceSq((double) this.gatePosition.getX(), this.theEntity.posY, (double) this.gatePosition.getZ()) <= MIN_DISTANCE) { this.gateBlock = this.getBlockFence(this.gatePosition); if (this.gateBlock != null) { return true; } } } } this.gatePosition = (new BlockPos(this.theEntity)).up(); this.gateBlock = this.getBlockFence(this.gatePosition); return this.gateBlock != null; }
@Override public String toString() { String result; if (noPath()) result = "No Path " + (getPath() != null ? getPath().getCurrentPathLength() : ""); else result = "Path to " + getPath().getPathPointFromIndex(getPath().getCurrentPathIndex()).toString(); if (hasMount() && !((EntityLiving) entity.getRidingEntity()).getNavigator().noPath()) { Path path = ((EntityLiving) entity.getRidingEntity()).getNavigator().getPath(); result += "AND Mount path to " + path.getPathPointFromIndex(path.getCurrentPathIndex()).toString(); } return result; } }
protected void pathFollow() { Vec3d vec3d = this.getEntityPosition(); int i = this.currentPath.getCurrentPathLength(); for (int j = this.currentPath.getCurrentPathIndex(); j < this.currentPath.getCurrentPathLength(); ++j) { if ((double) this.currentPath.getPathPointFromIndex(j).y != Math.floor(vec3d.y)) { i = j; break; } } this.maxDistanceToWaypoint = 0.49F ; Vec3d vec3d1 = this.currentPath.getCurrentPos(); if (MathHelper.abs((float) (this.entity.posX - (vec3d1.x + 0.5D))) < this.maxDistanceToWaypoint && MathHelper.abs((float) (this.entity.posZ - (vec3d1.z + 0.5D))) < this.maxDistanceToWaypoint && Math.abs(this.entity.posY - vec3d1.y) < 1.0D) { this.currentPath.setCurrentPathIndex(this.currentPath.getCurrentPathIndex() + 1); } int k = 1; int l = 1; int i1 = k; for (int j1 = i - 1; j1 >= this.currentPath.getCurrentPathIndex(); --j1) { if (this.isDirectPathBetweenPoints(vec3d, this.currentPath.getVectorFromIndex(this.entity, j1), k, l, i1)) { this.currentPath.setCurrentPathIndex(j1); break; } } this.checkForStuck(vec3d); }
protected void removeSunnyPath() { super.removeSunnyPath(); if (this.shouldAvoidSun) { if (this.world.canSeeSky(new BlockPos(MathHelper.floor(this.entity.posX), (int) (this.entity.getEntityBoundingBox().minY + 0.5D), MathHelper.floor(this.entity.posZ)))) { return; } for (int i = 0; i < this.currentPath.getCurrentPathLength(); ++i) { PathPoint pathpoint = this.currentPath.getPathPointFromIndex(i); if (this.world.canSeeSky(new BlockPos(pathpoint.x, pathpoint.y, pathpoint.z))) { this.currentPath.setCurrentPathLength(i - 1); return; } } } }
/** * Trims path data from the end to the first sun covered block */ protected void removeSunnyPath() { super.removeSunnyPath(); if (this.shouldAvoidSun) { if (this.world.canSeeSky(new BlockPos(MathHelper.floor(this.entity.posX), (int) (this.entity.getEntityBoundingBox().minY + 0.5D), MathHelper.floor(this.entity.posZ)))) { return; } for (int i = 0; i < this.currentPath.getCurrentPathLength(); ++i) { PathPoint pathpoint = this.currentPath.getPathPointFromIndex(i); if (this.world.canSeeSky(new BlockPos(pathpoint.x, pathpoint.y, pathpoint.z))) { this.currentPath.setCurrentPathLength(i - 1); return; } } } }
@Override protected void pathFollow() { Vec3d position = this.getEntityPosition(); int length = this.currentPath.getCurrentPathLength(); for (int i = this.currentPath.getCurrentPathIndex(); i < this.currentPath.getCurrentPathLength(); ++i) { if (this.currentPath.getPathPointFromIndex(i).y != Math.floor(position.y)) { length = i; break; } } Vec3d target = this.currentPath.getCurrentPos(); float deltaX = MathHelper.abs((float) (this.entity.posX - (target.x + 0.5))); float deltaZ = MathHelper.abs((float) (this.entity.posZ - (target.z + 0.5))); float deltaY = MathHelper.abs((float) (this.entity.posY - target.y)); int width = MathHelper.ceil(this.entity.width); int height = MathHelper.ceil(this.entity.height); float maxDistance = this.entity.width > 0.75F ? width : 0.75F - this.entity.width / 2.0F; if (deltaX < maxDistance && deltaZ < maxDistance && deltaY < 1.0) { this.currentPath.incrementPathIndex(); } for (int i = length - 1; i >= this.currentPath.getCurrentPathIndex(); --i) { if (this.isDirectPathBetweenPoints(position, this.currentPath.getVectorFromIndex(this.entity, i), width, height, width)) { this.currentPath.setCurrentPathIndex(i); break; } } this.checkForStuck(position); }
@NotNull final PathPointExtended pEx = (PathPointExtended) this.getPath().getPathPointFromIndex(this.getPath().getCurrentPathIndex()); if (curIndex > 0 && (curIndex + 1) < this.getPath().getCurrentPathLength() && this.getPath().getPathPointFromIndex(curIndex - 1).y != pEx.y)
PathPoint pathpoint2 = path.getPathPointFromIndex(j);
private void knockFromDamage(float val, Material material) { BlockPos pos = new BlockPos(this.posX, this.getEntityBoundingBox().minY + 0.5, this.posZ); if (world.getBlockState(pos.west()).getMaterial() == material) { knockBack(null, val, pos.getX() - 1 - this.posX, 0); } else if (world.getBlockState(pos.north()).getMaterial() == material) { knockBack(null, val, 0, pos.getZ() - 1 - this.posZ); } else if (world.getBlockState(pos.east()).getMaterial() == material) { knockBack(null, val, pos.getX() + 1 - this.posX, 0); } else if (world.getBlockState(pos.south()).getMaterial() == material) { knockBack(null, val, 0, pos.getZ() + 1 - this.posZ); } else if (world.getBlockState(pos.add(-1, 0, -1)).getMaterial() == material) { knockBack(null, val, pos.getX() - 1 - this.posX, pos.getZ() - 1 - this.posZ); } else if (world.getBlockState(pos.add(1, 0, -1)).getMaterial() == material) { knockBack(null, val, pos.getX() + 1 - this.posX, pos.getZ() - 1 - this.posZ); } else if (world.getBlockState(pos.add(-1, 0, 1)).getMaterial() == material) { knockBack(null, val, pos.getX() - 1 - this.posX, pos.getZ() + 1 - this.posZ); } else if (world.getBlockState(pos.add(1, 0, 1)).getMaterial() == material) { knockBack(null, val, pos.getX() + 1 - this.posX, pos.getZ() + 1 - this.posZ); } else if (world.getBlockState(pos.down()).getMaterial() == material) { knockBack(null, val, 2 * getRNG().nextFloat() - 1, 2 * getRNG().nextFloat() - 1); } if (world.isRemote || getNavigator().noPath()) return; PathPoint point = getNavigator().getPath().getPathPointFromIndex(getNavigator().getPath().getCurrentPathIndex()); if (world.getBlockState(new BlockPos(point.x, point.y, point.z)).getMaterial() == material) { getNavigator().clearPath(); } else if (world.getBlockState(new BlockPos(point.x, point.y - 1, point.z)).getMaterial() == material) { getNavigator().clearPath(); } }