From 9f12a0ab6f673921fcd0e2b6b266e557fa58cf16 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 21 Aug 2018 17:16:00 -0700 Subject: [PATCH] max fall height even with bucket, fixes #57 --- src/main/java/baritone/bot/Settings.java | 8 +++++++- .../bot/pathing/movement/CalculationContext.java | 15 +++++++++++---- .../bot/pathing/movement/MovementHelper.java | 2 +- .../pathing/movement/movements/MovementFall.java | 7 +++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/bot/Settings.java b/src/main/java/baritone/bot/Settings.java index fb079be0..1203a8a3 100644 --- a/src/main/java/baritone/bot/Settings.java +++ b/src/main/java/baritone/bot/Settings.java @@ -133,7 +133,13 @@ public class Settings { * 3 won't deal any damage. But if you just want to get down the mountain quickly and you have * Feather Falling IV, you might set it a bit higher, like 4 or 5. */ - public Setting maxFallHeight = new Setting<>(3); + public Setting maxFallHeightNoWater = new Setting<>(3); + + /** + * How far are you allowed to fall onto solid ground (with a water bucket)? + * It's not that reliable, so I've set it below what would kill an unarmored player (23) + */ + public Setting maxFallHeightBucket = new Setting<>(20); /** * If your goal is a GoalBlock in an unloaded chunk, assume it's far enough away that the Y coord diff --git a/src/main/java/baritone/bot/pathing/movement/CalculationContext.java b/src/main/java/baritone/bot/pathing/movement/CalculationContext.java index 03d4aba7..6bd09012 100644 --- a/src/main/java/baritone/bot/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/bot/pathing/movement/CalculationContext.java @@ -38,7 +38,8 @@ public class CalculationContext implements Helper { private final boolean canSprint; private final double placeBlockCost; private final boolean allowBreak; - private final int maxFallHeight; + private final int maxFallHeightNoWater; + private final int maxFallHeightBucket; public CalculationContext() { this(new ToolSet()); @@ -52,7 +53,8 @@ public class CalculationContext implements Helper { this.canSprint = Baritone.settings().allowSprint.get() && player().getFoodStats().getFoodLevel() > 6; this.placeBlockCost = Baritone.settings().blockPlacementPenalty.get(); this.allowBreak = Baritone.settings().allowBreak.get(); - this.maxFallHeight = Baritone.settings().maxFallHeight.get(); + this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get(); + this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get(); // why cache these things here, why not let the movements just get directly from settings? // because if some movements are calculated one way and others are calculated another way, // then you get a wildly inconsistent path that isn't optimal for either scenario. @@ -82,7 +84,12 @@ public class CalculationContext implements Helper { return allowBreak; } - public int maxFallHeight(){ - return maxFallHeight; + public int maxFallHeightNoWater() { + return maxFallHeightNoWater; } + + public int maxFallHeightBucket() { + return maxFallHeightBucket; + } + } diff --git a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java index 7e84a1cd..0d239b15 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java @@ -299,7 +299,7 @@ public interface MovementHelper extends ActionCosts, Helper { continue; } if (canWalkOn(onto, ontoBlock)) { - if (calcContext.hasWaterBucket() || fallHeight <= 4) { + if ((calcContext.hasWaterBucket() && fallHeight <= calcContext.maxFallHeightBucket() + 1) || fallHeight <= calcContext.maxFallHeightNoWater() + 1) { // fallHeight = 4 means onto.up() is 3 blocks down, which is the max return new MovementFall(pos, onto.up()); } else { diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java index aedec7e0..f98aca7d 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java @@ -52,10 +52,13 @@ public class MovementFall extends Movement { return COST_INF; } double placeBucketCost = 0.0; - if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeight()) { + if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeightNoWater()) { if (!context.hasWaterBucket()) { return COST_INF; } + if (src.getY() - dest.getY() > context.maxFallHeightBucket()) { + return COST_INF; + } placeBucketCost = context.placeBlockCost(); } double frontTwo = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0]) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[1]); @@ -89,7 +92,7 @@ public class MovementFall extends Movement { } BlockPos playerFeet = playerFeet(); Optional targetRotation = Optional.empty(); - if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > Baritone.settings().maxFallHeight.get() && !playerFeet.equals(dest)) { + if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > Baritone.settings().maxFallHeightNoWater.get() && !playerFeet.equals(dest)) { if (!player().inventory.hasItemStack(STACK_BUCKET_WATER) || world().provider.isNether()) { // TODO check if water bucket is on hotbar or main inventory state.setStatus(MovementStatus.UNREACHABLE); return state;