From 1745ce6a6241cd8e7c4d866ac52db5eed68981ba Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 15 Sep 2018 07:38:53 -0700 Subject: [PATCH] fix wrong y coordinate on path beginning --- .../baritone/pathing/path/PathExecutor.java | 17 +++++++++++------ src/main/java/baritone/utils/Helper.java | 8 +++++--- .../baritone/utils/pathing/BetterBlockPos.java | 5 +++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 734849ca..2b787a8a 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -20,13 +20,11 @@ package baritone.pathing.path; import baritone.Baritone; import baritone.api.event.events.TickEvent; import baritone.pathing.movement.*; -import baritone.pathing.movement.movements.MovementDescend; -import baritone.pathing.movement.movements.MovementDiagonal; -import baritone.pathing.movement.movements.MovementFall; -import baritone.pathing.movement.movements.MovementTraverse; +import baritone.pathing.movement.movements.*; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.Utils; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.init.Blocks; import net.minecraft.util.Tuple; import net.minecraft.util.math.BlockPos; @@ -78,9 +76,16 @@ public class PathExecutor implements Helper { if (pathPosition >= path.length() - 1) { return true; // stop bugging me, I'm done } - BlockPos whereShouldIBe = path.positions().get(pathPosition); - BlockPos whereAmI = playerFeet(); + BetterBlockPos whereShouldIBe = path.positions().get(pathPosition); + BetterBlockPos whereAmI = playerFeet(); if (!whereShouldIBe.equals(whereAmI)) { + + if (pathPosition == 0 && whereAmI.equals(whereShouldIBe.up()) && Math.abs(player().motionY) < 0.1) { + // avoid the Wrong Y coordinate bug + new MovementDownward(whereAmI, whereShouldIBe).update(); + return false; + } + //System.out.println("Should be at " + whereShouldIBe + " actually am at " + whereAmI); if (!Blocks.AIR.equals(BlockStateInterface.getBlock(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index 9bcf082d..0b729014 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -18,11 +18,11 @@ package baritone.utils; import baritone.Baritone; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.BlockSlab; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; @@ -52,9 +52,9 @@ public interface Helper { return mc.world; } - default BlockPos playerFeet() { + default BetterBlockPos playerFeet() { // TODO find a better way to deal with soul sand!!!!! - BlockPos feet = new BlockPos(player().posX, player().posY + 0.1251, player().posZ); + BetterBlockPos feet = new BetterBlockPos(player().posX, player().posY + 0.1251, player().posZ); if (BlockStateInterface.get(feet).getBlock() instanceof BlockSlab) { return feet.up(); } @@ -75,6 +75,7 @@ public interface Helper { /** * Send a message to chat only if chatDebug is on + * * @param message */ default void logDebug(String message) { @@ -88,6 +89,7 @@ public interface Helper { /** * Send a message to chat regardless of chatDebug (should only be used for critically important messages, or as a direct response to a chat command) + * * @param message */ default void logDirect(String message) { diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 895d982f..f908dd78 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -19,6 +19,7 @@ package baritone.utils.pathing; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3i; /** @@ -59,6 +60,10 @@ public final class BetterBlockPos extends BlockPos { this.hashCode = hash; } + public BetterBlockPos(double x, double y, double z) { + this(MathHelper.floor(x), MathHelper.floor(y), MathHelper.floor(z)); + } + public BetterBlockPos(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); }