From 31d1656c48633528afa511bad9bb683d58336884 Mon Sep 17 00:00:00 2001 From: Babbaj Date: Sat, 29 Jul 2023 00:22:52 -0400 Subject: [PATCH 1/2] safer landing --- .../java/baritone/process/ElytraProcess.java | 48 +++++++++++++------ .../process/elytra/ElytraBehavior.java | 4 ++ 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/process/ElytraProcess.java b/src/main/java/baritone/process/ElytraProcess.java index 126621ed9..ff374aad1 100644 --- a/src/main/java/baritone/process/ElytraProcess.java +++ b/src/main/java/baritone/process/ElytraProcess.java @@ -104,8 +104,18 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL); } - if (ctx.player().isElytraFlying() && this.state != State.LANDING) { + if (ctx.player().isElytraFlying() && this.state != State.LANDING && this.behavior.pathManager.isComplete()) { final BetterBlockPos last = this.behavior.pathManager.path.getLast(); + if (last != null && ctx.player().getDistanceSqToCenter(last) < (48 * 48) && !goingToLandingSpot) { + BetterBlockPos landingSpot = findSafeLandingSpot(last); + // if this fails we will just keep orbiting the last node until we run out of rockets or the user intervenes + if (landingSpot != null) { + this.pathTo(landingSpot); + this.landingSpot = landingSpot; + this.goingToLandingSpot = true; + } + } + if (last != null && ctx.player().getDistanceSqToCenter(last) < 1) { if (Baritone.settings().notificationOnPathComplete.value && !reachedGoal) { logNotification("Pathing complete", false); @@ -118,16 +128,8 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro } reachedGoal = true; - if (!goingToLandingSpot) { - BetterBlockPos landingSpot = findSafeLandingSpot(); - // if this fails we will just keep orbiting the last node until we run out of rockets or the user intervenes - if (landingSpot != null) { - this.pathTo(landingSpot); - this.landingSpot = landingSpot; - this.goingToLandingSpot = true; - } - } else { - // we are goingToLandingSpot and we are in the in the last node of the path + // we are goingToLandingSpot and we are in the last node of the path + if (this.goingToLandingSpot) { this.state = State.LANDING; } } @@ -423,6 +425,25 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro return true; } + private boolean hasAirBubble(BlockPos pos) { + final int radius = 2; // Half of 5, as we're counting blocks in each direction from the center + + for (int x = -radius; x <= radius; x++) { + for (int y = -radius; y <= radius; y++) { + for (int z = -radius; z <= radius; z++) { + BlockPos currentPos = pos.add(x, y, z); + IBlockState blockState = ctx.world().getBlockState(currentPos); + + if (blockState.getBlock() != Blocks.AIR) { + return false; + } + } + } + } + + return true; + } + private BetterBlockPos checkLandingSpot(BlockPos pos, LongOpenHashSet checkedSpots) { BlockPos.MutableBlockPos mut = new BlockPos.MutableBlockPos(pos); while (mut.getY() >= 0) { @@ -445,8 +466,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro return null; // void } - private BetterBlockPos findSafeLandingSpot() { - final BetterBlockPos start = ctx.playerFeet(); + private BetterBlockPos findSafeLandingSpot(BetterBlockPos start) { Queue queue = new PriorityQueue<>(Comparator.comparingInt(pos -> (pos.x - start.x) * (pos.x - start.x) + (pos.z - start.z) * (pos.z - start.z)).thenComparingInt(pos -> -pos.y)); Set visited = new HashSet<>(); LongOpenHashSet checkedPositions = new LongOpenHashSet(); @@ -456,7 +476,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro BetterBlockPos pos = queue.poll(); if (ctx.world().isBlockLoaded(pos) && isInBounds(pos) && ctx.world().getBlockState(pos).getBlock() == Blocks.AIR) { BetterBlockPos actualLandingSpot = checkLandingSpot(pos, checkedPositions); - if (actualLandingSpot != null && isColumnAir(actualLandingSpot, 15)) { + if (actualLandingSpot != null && isColumnAir(actualLandingSpot, 15) && hasAirBubble(actualLandingSpot.up(15))) { return actualLandingSpot.up(15); } if (visited.add(pos.north())) queue.add(pos.north()); diff --git a/src/main/java/baritone/process/elytra/ElytraBehavior.java b/src/main/java/baritone/process/elytra/ElytraBehavior.java index c0cd07c87..9311b296c 100644 --- a/src/main/java/baritone/process/elytra/ElytraBehavior.java +++ b/src/main/java/baritone/process/elytra/ElytraBehavior.java @@ -366,6 +366,10 @@ public final class ElytraBehavior implements Helper { } this.playerNear = index; } + + public boolean isComplete() { + return this.completePath; + } } public void onRenderPass(RenderEvent event) { From 2e2c0ecc0b895c68c92be21ce2bf1b36df494576 Mon Sep 17 00:00:00 2001 From: Babbaj Date: Sat, 29 Jul 2023 11:52:37 -0400 Subject: [PATCH 2/2] use MutableBlockPos --- src/main/java/baritone/process/ElytraProcess.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/process/ElytraProcess.java b/src/main/java/baritone/process/ElytraProcess.java index ff374aad1..ca6988b20 100644 --- a/src/main/java/baritone/process/ElytraProcess.java +++ b/src/main/java/baritone/process/ElytraProcess.java @@ -427,14 +427,12 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro private boolean hasAirBubble(BlockPos pos) { final int radius = 2; // Half of 5, as we're counting blocks in each direction from the center - + BlockPos.MutableBlockPos mut = new BlockPos.MutableBlockPos(); for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { - BlockPos currentPos = pos.add(x, y, z); - IBlockState blockState = ctx.world().getBlockState(currentPos); - - if (blockState.getBlock() != Blocks.AIR) { + mut.setPos(pos.getX() + x, pos.getY() + y, pos.getZ() + z); + if (!ctx.world().isAirBlock(mut)) { return false; } }