From 18431d78e3957e702ac92c1e989bba4f21fc32c9 Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Wed, 8 Aug 2018 12:51:04 -0700 Subject: [PATCH] Refactor moveTowards to be more stateful --- .../baritone/bot/pathing/movement/Movement.java | 5 ----- .../bot/pathing/movement/MovementHelper.java | 14 +++++++++++--- .../pathing/movement/movements/MovementAscend.java | 2 +- .../movement/movements/MovementDescend.java | 2 +- .../movement/movements/MovementDiagonal.java | 2 +- .../movement/movements/MovementDownward.java | 2 +- .../movement/movements/MovementTraverse.java | 4 ++-- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java index 461069b7..01c88a3b 100644 --- a/src/main/java/baritone/bot/pathing/movement/Movement.java +++ b/src/main/java/baritone/bot/pathing/movement/Movement.java @@ -236,9 +236,4 @@ public abstract class Movement implements Helper, MovementHelper { toPlaceCached = result; return result; } - - protected void moveTowards(BlockPos pos) { - currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), playerRotations()).getFirst(), player().rotationPitch))) - .setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); - } } diff --git a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java index a054654a..29a42efb 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java @@ -17,12 +17,12 @@ package baritone.bot.pathing.movement; +import baritone.bot.InputOverrideHandler; import baritone.bot.behavior.impl.LookBehaviorUtils; +import baritone.bot.pathing.movement.MovementState.MovementTarget; import baritone.bot.pathing.movement.movements.MovementDescend; import baritone.bot.pathing.movement.movements.MovementFall; -import baritone.bot.utils.BlockStateInterface; -import baritone.bot.utils.Helper; -import baritone.bot.utils.ToolSet; +import baritone.bot.utils.*; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -35,6 +35,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; import java.util.Arrays; import java.util.List; @@ -201,6 +202,13 @@ public interface MovementHelper extends ActionCosts, Helper { return false; } + static MovementState moveTowards(MovementState state, BlockPos pos) { + return state.setTarget(new MovementTarget(new Rotation(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), + new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), + new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)).getFirst(), mc.player.rotationPitch)) + ).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); + } + static Movement generateMovementFallOrDescend(BlockPos pos, EnumFacing direction) { BlockPos dest = pos.offset(direction); BlockPos destUp = dest.up(); diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java index 913d1fa4..ac4ec193 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java @@ -93,7 +93,7 @@ public class MovementAscend extends Movement { state.setStatus(MovementStatus.SUCCESS); return state; } - moveTowards(positionsToBreak[0]); + MovementHelper.moveTowards(state, positionsToBreak[0]); return state.setInput(InputOverrideHandler.Input.JUMP, true); default: return state; diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java index f2d7b633..ca636a0d 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java @@ -75,7 +75,7 @@ public class MovementDescend extends Movement { double diffZ2 = player().posZ - (fakeDest.getZ() + 0.5); double d = Math.sqrt(diffX2 * diffX2 + diffZ2 * diffZ2); if (d > ab) - moveTowards(fakeDest); + MovementHelper.moveTowards(state, fakeDest); else { state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, false); state.setInput(InputOverrideHandler.Input.MOVE_BACK, true); diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDiagonal.java index 593a7133..7bf3814f 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDiagonal.java @@ -58,7 +58,7 @@ public class MovementDiagonal extends Movement { state.setStatus(MovementState.MovementStatus.SUCCESS); return state; } - moveTowards(dest); + MovementHelper.moveTowards(state, dest); return state; } diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java index 0ac0b4af..7fd43e9a 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java @@ -71,7 +71,7 @@ public class MovementDownward extends Movement { if (numTicks++ < 10 && ab < 0.2) { return state; } - moveTowards(positionsToBreak[0]); + MovementHelper.moveTowards(state, positionsToBreak[0]); return state; default: return state; diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java index 3c144819..ac785f48 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java @@ -133,7 +133,7 @@ public class MovementTraverse extends Movement { if (wasTheBridgeBlockAlwaysThere) { // player().setSprinting(true); } - moveTowards(positionsToBreak[0]); + MovementHelper.moveTowards(state, positionsToBreak[0]); return state; } else { wasTheBridgeBlockAlwaysThere = false; @@ -185,7 +185,7 @@ public class MovementTraverse extends Movement { // Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt()); return state; } else { - moveTowards(positionsToBreak[0]); + MovementHelper.moveTowards(state, positionsToBreak[0]); return state; // TODO MovementManager.moveTowardsBlock(to); // move towards not look at because if we are bridging for a couple blocks in a row, it is faster if we dont spin around and walk forwards then spin around and place backwards for every block }