use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
the class IPath method sanityCheck.
/**
* Performs a series of checks to ensure that the assembly of the path went as expected.
*/
default void sanityCheck() {
List<BetterBlockPos> path = positions();
List<IMovement> movements = movements();
if (!getSrc().equals(path.get(0))) {
throw new IllegalStateException("Start node does not equal first path element");
}
if (!getDest().equals(path.get(path.size() - 1))) {
throw new IllegalStateException("End node does not equal last path element");
}
if (path.size() != movements.size() + 1) {
throw new IllegalStateException("Size of path array is unexpected");
}
HashSet<BetterBlockPos> seenSoFar = new HashSet<>();
for (int i = 0; i < path.size() - 1; i++) {
BetterBlockPos src = path.get(i);
BetterBlockPos dest = path.get(i + 1);
IMovement movement = movements.get(i);
if (!src.equals(movement.getSrc())) {
throw new IllegalStateException("Path source is not equal to the movement source");
}
if (!dest.equals(movement.getDest())) {
throw new IllegalStateException("Path destination is not equal to the movement destination");
}
if (seenSoFar.contains(src)) {
throw new IllegalStateException("Path doubles back on itself, making a loop");
}
seenSoFar.add(src);
}
}
use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
the class WaypointCollection method load.
private synchronized void load(Waypoint.Tag tag) {
this.waypoints.put(tag, new HashSet<>());
Path fileName = this.directory.resolve(tag.name().toLowerCase() + ".mp4");
if (!Files.exists(fileName)) {
return;
}
try (FileInputStream fileIn = new FileInputStream(fileName.toFile());
BufferedInputStream bufIn = new BufferedInputStream(fileIn);
DataInputStream in = new DataInputStream(bufIn)) {
long magic = in.readLong();
if (magic != WAYPOINT_MAGIC_VALUE) {
throw new IOException("Bad magic value " + magic);
}
// Yes I want 9,223,372,036,854,775,807 waypoints, do you not?
long length = in.readLong();
while (length-- > 0) {
String name = in.readUTF();
long creationTimestamp = in.readLong();
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
this.waypoints.get(tag).add(new Waypoint(name, tag, new BetterBlockPos(x, y, z), creationTimestamp));
}
} catch (IOException ignored) {
}
}
use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
the class FindCommand method execute.
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
List<Block> toFind = new ArrayList<>();
while (args.hasAny()) {
toFind.add(args.getDatatypeFor(BlockById.INSTANCE));
}
BetterBlockPos origin = ctx.playerFeet();
toFind.stream().flatMap(block -> ctx.worldData().getCachedWorld().getLocationsOf(Block.REGISTRY.getNameForObject(block).getPath(), Integer.MAX_VALUE, origin.x, origin.y, 4).stream()).map(BetterBlockPos::new).map(BetterBlockPos::toString).forEach(this::logDirect);
}
use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
the class MovementDiagonal method safeToCancel.
@Override
protected boolean safeToCancel(MovementState state) {
// too simple. backfill does not work after cornering with this
// return MovementHelper.canWalkOn(ctx, ctx.playerFeet().down());
EntityPlayerSP player = ctx.player();
double offset = 0.25;
double x = player.posX;
double y = player.posY - 1;
double z = player.posZ;
// standard
if (ctx.playerFeet().equals(src)) {
return true;
}
// both corners are walkable
if (MovementHelper.canWalkOn(ctx, new BlockPos(src.x, src.y - 1, dest.z)) && MovementHelper.canWalkOn(ctx, new BlockPos(dest.x, src.y - 1, src.z))) {
return true;
}
// we are in a likely unwalkable corner, check for a supporting block
if (ctx.playerFeet().equals(new BetterBlockPos(src.x, src.y, dest.z)) || ctx.playerFeet().equals(new BetterBlockPos(dest.x, src.y, src.z))) {
return (MovementHelper.canWalkOn(ctx, new BetterBlockPos(x + offset, y, z + offset)) || MovementHelper.canWalkOn(ctx, new BetterBlockPos(x + offset, y, z - offset)) || MovementHelper.canWalkOn(ctx, new BetterBlockPos(x - offset, y, z + offset)) || MovementHelper.canWalkOn(ctx, new BetterBlockPos(x - offset, y, z - offset)));
}
return true;
}
use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
the class MovementDiagonal method calculateValidPositions.
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
BetterBlockPos diagA = new BetterBlockPos(src.x, src.y, dest.z);
BetterBlockPos diagB = new BetterBlockPos(dest.x, src.y, src.z);
if (dest.y < src.y) {
return ImmutableSet.of(src, dest.up(), diagA, diagB, dest, diagA.down(), diagB.down());
}
if (dest.y > src.y) {
return ImmutableSet.of(src, src.up(), diagA, diagB, dest, diagA.up(), diagB.up());
}
return ImmutableSet.of(src, dest, diagA, diagB);
}
Aggregations