From b55a102d37008e1b7197003152797d01ccf4210c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 1 Oct 2018 14:26:55 -0700 Subject: [PATCH] take depth strider into acocunt for water speed, fixes #101 --- .../pathing/movement/CalculationContext.java | 15 ++++++++++++++- .../movement/movements/MovementDiagonal.java | 2 +- .../movement/movements/MovementTraverse.java | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 3149cfe9..ee4cb188 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -18,8 +18,10 @@ package baritone.pathing.movement; import baritone.Baritone; +import baritone.api.pathing.movement.ActionCosts; import baritone.utils.Helper; import baritone.utils.ToolSet; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -40,6 +42,7 @@ public class CalculationContext implements Helper { private final boolean allowBreak; private final int maxFallHeightNoWater; private final int maxFallHeightBucket; + private final double waterWalkSpeed; public CalculationContext() { this(new ToolSet()); @@ -54,13 +57,19 @@ public class CalculationContext implements Helper { this.allowBreak = Baritone.settings().allowBreak.get(); this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get(); this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get(); + int depth = EnchantmentHelper.getDepthStriderModifier(player()); + if (depth > 3) { + depth = 3; + } + float mult = depth / 3.0F; + this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - mult) + ActionCosts.WALK_ONE_BLOCK_COST * mult; // 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. } public ToolSet getToolSet() { - return this.toolSet; + return toolSet; } public boolean hasWaterBucket() { @@ -91,4 +100,8 @@ public class CalculationContext implements Helper { return maxFallHeightBucket; } + public double waterWalkSpeed() { + return waterWalkSpeed; + } + } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 454421c4..a1e68dfe 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -122,7 +122,7 @@ public class MovementDiagonal extends Movement { // Ignore previous multiplier // Whatever we were walking on (possibly soul sand) doesn't matter as we're actually floating on water // Not even touching the blocks below - multiplier = WALK_ONE_IN_WATER_COST; + multiplier = context.waterWalkSpeed(); water = true; } if (optionA != 0 || optionB != 0) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 72bfa526..26952b02 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -69,7 +69,7 @@ public class MovementTraverse extends Movement { double WC = WALK_ONE_BLOCK_COST; boolean water = false; if (BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock())) { - WC = WALK_ONE_IN_WATER_COST; + WC = context.waterWalkSpeed(); water = true; } else { if (destOn.getBlock() == Blocks.SOUL_SAND) { @@ -116,7 +116,7 @@ public class MovementTraverse extends Movement { } double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb1, true); - double WC = throughWater ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST; + double WC = throughWater ? context.waterWalkSpeed() : WALK_ONE_BLOCK_COST; for (int i = 0; i < 4; i++) { int againstX = destX + HORIZONTALS[i].getXOffset(); int againstZ = destZ + HORIZONTALS[i].getZOffset();