diff --git a/src/main/java/baritone/Elytra.java b/src/main/java/baritone/Elytra.java index 69fee5450..77a09f369 100644 --- a/src/main/java/baritone/Elytra.java +++ b/src/main/java/baritone/Elytra.java @@ -48,6 +48,16 @@ public class Elytra extends Behavior implements Helper { private long context; private Long seed; + public int playerNear; + public int goingTo; + public int sinceFirework; + public BlockPos goal; + public List> lines = new ArrayList<>(); + + protected Elytra(Baritone baritone) { + super(baritone); + } + public void path(long seed, BlockPos destination) { this.setupContext(seed); @@ -87,11 +97,6 @@ public class Elytra extends Behavior implements Helper { this.context = 0; } - public int playerNear; - public int goingTo; - public int sinceFirework; - public BlockPos goal; - public void cancel() { this.path.clear(); this.goal = null; @@ -100,147 +105,10 @@ public class Elytra extends Behavior implements Helper { this.sinceFirework = 0; } - private void pathfindAroundObstacles() { - outer: - while (true) { - int rangeStartIncl = playerNear; - int rangeEndExcl = playerNear; - while (rangeEndExcl < path.size() && ctx.world().isBlockLoaded(path.get(rangeEndExcl), false)) { - rangeEndExcl++; - } - if (rangeStartIncl >= rangeEndExcl) { - // not loaded yet? - return; - } - if (!passable(ctx.world().getBlockState(path.get(rangeStartIncl)))) { - // we're in a wall - return; // previous iterations of this function SHOULD have fixed this by now :rage_cat: - } - for (int i = rangeStartIncl; i < rangeEndExcl - 1; i++) { - if (!clearView(pathAt(i), pathAt(i + 1))) { - // obstacle. where do we return to pathing? - // find the next valid segment - for (int j = i + 1; j < rangeEndExcl - 1; j++) { - if (clearView(pathAt(j), pathAt(j + 1))) { - // found it - // path from i to j - List newPath = simplePathfind(path.get(i), path.get(j)); - if (newPath == null) { - logDirect("no path"); - return; - } - path.subList(i + 1, j).clear(); - for (int k = newPath.size() - 1; k >= 0; k--) { - path.add(i + 1, newPath.get(k)); - } - logDirect("replaced path starting at " + path.get(i)); - removeBacktracks(); - break outer; // eventually "continue outer" - } - } - } - } - break; - } - } - - private int manhattanDist(BlockPos start, BlockPos dest) { - return Math.abs(start.getX() - dest.getX()) + Math.abs(start.getY() - dest.getY()) + Math.abs(start.getZ() - dest.getZ()); - } - - private class SearchNode { - BetterBlockPos pos; - int dist; - int heuristic; - SearchNode prev; - boolean canceled; - - public SearchNode(BetterBlockPos pos, int dist, int heuristic, SearchNode prev) { - this.pos = pos; - this.dist = dist; - this.heuristic = heuristic; - this.prev = prev; - } - } - - private List simplePathfind(BetterBlockPos start, BetterBlockPos dest) { - Map map = new HashMap<>(); - PriorityQueue queue = new PriorityQueue<>(Comparator.comparingInt(node -> node.dist + node.heuristic)); - SearchNode origin = new SearchNode(start, 0, manhattanDist(start, dest) * 10, null); - map.put(start, origin); - queue.add(origin); - int count = 0; - while (!queue.isEmpty()) { - if (count++ > 10000) { - logDirect("oopsie"); - return null; - } - SearchNode node = queue.poll(); - if (node.canceled) { - continue; - } - if (node.pos.equals(dest)) { - List path = new ArrayList<>(); - while (node != null) { - path.add(node.pos); - node = node.prev; - } - Collections.reverse(path); - return simplify(path); - } - BetterBlockPos[] adjs = new BetterBlockPos[]{node.pos.up(), node.pos.down(), node.pos.north(), node.pos.south(), node.pos.east(), node.pos.west()}; - boolean nearAWall = false; - for (BetterBlockPos adj : adjs) { - if (!passable(ctx.world().getBlockState(adj))) { - nearAWall = true; - break; - } - } - for (BetterBlockPos adj : adjs) { - if (!passable(ctx.world().getBlockState(adj))) { - continue; - } - int cost = node.dist + (nearAWall ? 11 : 10); - if (map.containsKey(adj)) { - if (map.get(adj).dist <= cost) { - continue; - } - map.get(adj).canceled = true; - } - map.put(adj, new SearchNode(adj, cost, manhattanDist(adj, dest) * 10, node)); - queue.add(map.get(adj)); - } - } - return null; - } - - private List simplify(List path) { - List simplified = new ArrayList<>(path); - for (int i = 0; i < simplified.size() - 2; i++) { - BlockPos dir = simplified.get(i + 1).subtract(simplified.get(i)); - while (i + 2 < simplified.size()) { - if (simplified.get(i + 2).subtract(simplified.get(i + 1)).equals(dir)) { - simplified.remove(i + 1); - } else { - break; - } - } - } - return simplified; - } - private Vec3d pathAt(int i) { return new Vec3d(path.get(i).x + 0.5, path.get(i).y + 0.5, path.get(i).z + 0.5); } - - public List> lines = new ArrayList<>(); - - protected Elytra(Baritone baritone) { - super(baritone); - } - - @Override public void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { @@ -252,7 +120,6 @@ public class Elytra extends Behavior implements Helper { fixNearPlayer(); baritone.getInputOverrideHandler().clearAllKeys(); lines.clear(); - pathfindAroundObstacles(); if (ctx.player().isElytraFlying()) { if (ctx.player().collidedHorizontally) { logDirect("hbonk"); @@ -323,7 +190,9 @@ public class Elytra extends Behavior implements Helper { } private boolean firework() { - return ctx.world().loadedEntityList.stream().anyMatch(x -> (x instanceof EntityFireworkRocket) && ((EntityFireworkRocket) x).isAttachedToEntity()); + // TODO: Validate that the EntityFireworkRocket is attached to ctx.player() + return ctx.world().loadedEntityList.stream() + .anyMatch(x -> (x instanceof EntityFireworkRocket) && ((EntityFireworkRocket) x).isAttachedToEntity()); } private boolean isClear(Vec3d start, Vec3d dest) { @@ -390,7 +259,7 @@ public class Elytra extends Behavior implements Helper { return state.getMaterial() == Material.AIR; } - public static Vec3d step(Vec3d motion, float rotationPitch, float rotationYaw, boolean firework) { + private static Vec3d step(Vec3d motion, float rotationPitch, float rotationYaw, boolean firework) { double motionX = motion.x; double motionY = motion.y; double motionZ = motion.z; @@ -438,7 +307,7 @@ public class Elytra extends Behavior implements Helper { return new Vec3d(motionX, motionY, motionZ); } - public void fixNearPlayer() { + private void fixNearPlayer() { BetterBlockPos pos = ctx.playerFeet(); for (int i = playerNear; i >= Math.max(playerNear - 1000, 0); i -= 10) { if (path.get(i).distanceSq(pos) < path.get(playerNear).distanceSq(pos)) { @@ -463,7 +332,7 @@ public class Elytra extends Behavior implements Helper { //System.out.println(playerNear); } - public void removeBacktracks() { + private void removeBacktracks() { Map positionFirstSeen = new HashMap<>(); for (int i = 0; i < path.size(); i++) { BetterBlockPos pos = path.get(i); @@ -479,7 +348,8 @@ public class Elytra extends Behavior implements Helper { } } - public RayTraceResult rayTraceBlocks(Vec3d start, Vec3d end) { + // TODO: Use the optimized version from builder-2 + private RayTraceResult rayTraceBlocks(Vec3d start, Vec3d end) { int x1 = MathHelper.floor(end.x); int y1 = MathHelper.floor(end.y); int z1 = MathHelper.floor(end.z);