@Override protected void pathFollow() { Vec3d vec3d = this.getEntityPosition(); float f = this.entity.width * this.entity.width; int i = 6; if (vec3d.squareDistanceTo(this.currentPath.getVectorFromIndex(this.entity, this.currentPath.getCurrentPathIndex())) < (double) f) { this.currentPath.incrementPathIndex(); } for (int j = Math.min(this.currentPath.getCurrentPathIndex() + 6, this.currentPath.getCurrentPathLength() - 1); j > this.currentPath.getCurrentPathIndex(); --j) { Vec3d vec3d1 = this.currentPath.getVectorFromIndex(this.entity, j); if (vec3d1.squareDistanceTo(vec3d) <= 36.0D && this.isDirectPathBetweenPoints(vec3d, vec3d1, 0, 0, 0)) { this.currentPath.setCurrentPathIndex(j); break; } } this.checkForStuck(vec3d); }
/** * Returns whether or not a citizen is heading to a specific location. * * @param citizen Citizen you want to check * @param x X-coordinate * @param z Z-coordinate * @return True if citizen heads to (x, z), otherwise false */ public static boolean isPathingTo(@NotNull final EntityCitizen citizen, final int x, final int z) { final PathPoint pathpoint = citizen.getNavigator().getPath().getFinalPathPoint(); return pathpoint != null && pathpoint.x == x && pathpoint.z == z; }
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 float getJumpUpwardsMotion() { if (!collidedHorizontally && (!moveHelper.isUpdating() || moveHelper.getY() <= posY + 0.5D)) { Path path = navigator.getPath(); if (path != null && path.getCurrentPathIndex() < path.getCurrentPathLength()) { Vec3d vec3d = path.getPosition(this); if (vec3d.y > posY + 0.5D) return 0.5F; } return moveHelper.getSpeed() <= 0.6D ? 0.5F : 0.5F; } else { return 0.5F; } }
pathResult.setPathLength(getPath().getCurrentPathLength()); pathResult.setStatus(PathResult.Status.IN_PROGRESS_FOLLOWING); final PathPoint p = getPath().getFinalPathPoint(); if (p != null && destination == null) int oldIndex = this.noPath() ? 0 : this.getPath().getCurrentPathIndex(); super.onUpdateNavigation(); @NotNull final PathPointExtended pEx = (PathPointExtended) this.getPath().getPathPointFromIndex(this.getPath().getCurrentPathIndex()); Vec3d vec3 = this.getPath().getPosition(this.ourEntity); final int curIndex = this.getPath().getCurrentPathIndex(); if (curIndex > 0 && (curIndex + 1) < this.getPath().getCurrentPathLength() && this.getPath().getPathPointFromIndex(curIndex - 1).y != pEx.y) this.getPath().setCurrentPathIndex(oldIndex); Vec3d vec3d = this.getPath().getPosition(this.ourEntity); this.getPath().setCurrentPathIndex(this.getPath().getCurrentPathIndex() + 1); if (this.noPath()) vec3d = this.getPath().getPosition(this.ourEntity);
@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; } }
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; } } } }
text.println("Length: " + path.getCurrentPathLength()); text.println("Index: " + path.getCurrentPathIndex()); PathPoint finalPoint = path.getFinalPathPoint(); text.println("Final point: " + finalPoint);
@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); }
); if (path == null || path.getCurrentPathLength() == 0) { return MethodResult.failure("No path exists"); if (!context.getCostHandler().consume(path.getCurrentPathLength() * 5 * speed)) { return MethodResult.failure("Insufficient energy");
@Override public void updateTask() { Path currentPath = this.dinosaur.getNavigator().getPath(); if (this.path != null) { PathPoint finalPathPoint = this.path.getFinalPathPoint(); if (currentPath == null || !currentPath.getFinalPathPoint().equals(finalPathPoint)) { Path path = this.dinosaur.getNavigator().getPathToXYZ(finalPathPoint.x, finalPathPoint.y, finalPathPoint.z); this.dinosaur.getNavigator().setPath(path, 1.0); this.path = path; } } if (this.giveUpTime <= 0 || (this.dinosaur.getStayAwakeTime() <= 0 && (this.path == null || this.path.isFinished()))) { this.dinosaur.setSleeping(true); } this.giveUpTime--; }
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(); } }
final int currentIndex = worker.getNavigator().getPath().getCurrentPathIndex();
@Override public void onUpdateNavigation() { ++totalTicksLocal; if (!noPath()) { // if we have a path // theEntity.onGround = false; // theEntity.isAirBorne = true; pathFollow(); // follow it if (!noPath() && currentPath != null) { // if we haven't finished, then set the new move point Vec3d targetPos = currentPath.getPosition(entity); double y = targetPos.y; if (forceFlying) { double aboveBlock = y - (int) y; if (aboveBlock < 0.10) { y = (int) y + 0.10; } } entity.getMoveHelper().setMoveTo(targetPos.x, y, targetPos.z, speed); } } }
@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; } }
/** * 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 public void updateAITasks() { if (currentMoveTypeDuration > 0) { --currentMoveTypeDuration; } if (onGround) { if (!wasOnGround) { setJumping(false); checkLandingDelay(); } EntityGrasshopper.GrasshopperJumpHelper grasshopperjumphelper = (EntityGrasshopper.GrasshopperJumpHelper) jumpHelper; if (!grasshopperjumphelper.getIsJumping()) { if (moveHelper.isUpdating() && currentMoveTypeDuration == 0) { Path path = navigator.getPath(); Vec3d vec3d = new Vec3d(moveHelper.getX(), moveHelper.getY(), moveHelper.getZ()); if (path != null && path.getCurrentPathIndex() < path.getCurrentPathLength()) vec3d = path.getPosition(this); calculateRotationYaw(vec3d.x, vec3d.z); startJumping(); } } else if (!grasshopperjumphelper.canJump()) enableJumpControl(); } wasOnGround = onGround; }
public BlockPos getClosestFeeder() { if (this.ticksExisted - this.feederSearchTick > 200) { this.feederSearchTick = this.ticksExisted; OnionTraverser traverser = new OnionTraverser(this.getPosition(), 32); for (BlockPos pos : traverser) { IBlockState state = this.world.getBlockState(pos); if (state.getBlock() instanceof FeederBlock) { TileEntity tile = this.world.getTileEntity(pos); if (tile instanceof FeederBlockEntity) { FeederBlockEntity feeder = (FeederBlockEntity) tile; if (feeder.canFeedDinosaur(this) && feeder.getFeeding() == null && feeder.openAnimation == 0) { Path path = this.getNavigator().getPathToPos(pos); if (path != null && path.getCurrentPathLength() != 0) { return this.closestFeeder = pos; } } } } } } return this.closestFeeder; }