use of com.adamki11s.pathing.Tile in project CyanBot by XjCyan1de.
the class MoveTask method moveAlong.
private void moveAlong(final Location start, ArrayList<Tile> tiles) {
Timer timer = new Timer();
final Iterator<Tile> itr = tiles.iterator();
TimerTask task = new TimerTask() {
@Override
public void run() {
if (itr.hasNext()) {
Tile t = itr.next();
Location loc = t.getLocation(start);
// c.gui.addText("Position is: " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ());
// c.chat.sendMessage("Trying to move to: " + loc);
calcMovement(new Location(loc.getBlockX() + 0.5, loc.getBlockY(), loc.getBlockZ() + 0.5));
/* if(next != null){
Location loc = next.getLocation(start);
next = itr.next();
Location locs = next.getLocation(start);
double newYaw = 0, newPitch = 0;
double xDiff = locs.getX() - c.location.getX();
double yDiff = locs.getY() - (c.location.getY() - 1);
double zDiff = locs.getZ() - c.location.getZ();
double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90;
if(zDiff < 0.0) {
newYaw = newYaw + Math.abs(180 - newYaw) * 2;
}
c.yaw = (float) newYaw;
c.pitch = (float) newPitch;
if(!itr.hasNext()){
next = null;
}
calcMovement(new Location(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}else{
Tile t = itr.next();
next = itr.next();
Location locs = next.getLocation(start);
double newYaw = 0, newPitch = 0;
double xDiff = locs.getX() - c.location.getX();
double yDiff = locs.getY() - (c.location.getY() - 1);
double zDiff = locs.getZ() - c.location.getZ();
double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90;
if(zDiff < 0.0) {
newYaw = newYaw + Math.abs(180 - newYaw) * 2;
}
Location loc = t.getLocation(start);
calcMovement(new Location(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}*/
} else {
this.cancel();
}
}
};
timer.scheduleAtFixedRate(task, 0, 100);
}
use of com.adamki11s.pathing.Tile in project CyanBot by XjCyan1de.
the class MoveTask method runPathing.
public void runPathing(final Location start, final Location end, final int range) {
try {
// create our pathfinder
AStar path = new AStar(bot.getWorld(), start, end, range);
// get the list of nodes to walk to as a Tile object
ArrayList<Tile> route = path.iterate();
// get the result of the path trace
PathingResult result = path.getPathingResult();
switch(result) {
case SUCCESS:
// Path was successful. Do something here.
moveAlong(start, route);
System.out.println("Path was found! :D");
break;
case NO_PATH:
// No path found, throw error.
System.out.println("No path found!");
// c.chat.sendMessage("No path was found :(");
break;
default:
// c.chat.sendMessage("Well... appearently we didn't find a path and we did... at the same time");
break;
}
} catch (AStar.InvalidPathException e) {
// InvalidPathException will be thrown if start or end block is air
if (e.isEndNotSolid()) {
// System.out.println("End block is not walkable");
// c.chat.sendMessage("Unable to walk on the block you are standing on.");
}
if (e.isStartNotSolid()) {
System.out.println("Start block is not walkable");
}
}
}