From 3c6415d48634b333d955b75dfb532dba0b997721 Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Sun, 5 Aug 2018 20:50:59 -0400 Subject: [PATCH] Fix target creation of Movement superclass --- .../baritone/bot/behavior/impl/LookBehaviorUtils.java | 11 ++++++----- .../java/baritone/bot/pathing/movement/Movement.java | 11 +++++------ .../baritone/bot/pathing/movement/MovementState.java | 6 +++--- src/main/java/baritone/bot/utils/Utils.java | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/baritone/bot/behavior/impl/LookBehaviorUtils.java b/src/main/java/baritone/bot/behavior/impl/LookBehaviorUtils.java index 25724b5c..8c9c14c5 100644 --- a/src/main/java/baritone/bot/behavior/impl/LookBehaviorUtils.java +++ b/src/main/java/baritone/bot/behavior/impl/LookBehaviorUtils.java @@ -2,6 +2,7 @@ package baritone.bot.behavior.impl; import baritone.bot.utils.BlockStateInterface; import baritone.bot.utils.Helper; +import baritone.bot.utils.Rotation; import baritone.bot.utils.Utils; import net.minecraft.block.state.IBlockState; import net.minecraft.util.Tuple; @@ -34,7 +35,7 @@ public final class LookBehaviorUtils implements Helper{ return new Vec3d((double) (f1 * f2), (double) f3, (double) (f * f2)); } - public static Optional> reachable(BlockPos pos) { + public static Optional reachable(BlockPos pos) { Optional possibleRotation = reachableCenter(pos); if(possibleRotation.isPresent()) { return possibleRotation; @@ -72,8 +73,8 @@ public final class LookBehaviorUtils implements Helper{ * @param offset * @return */ - protected static Optional> reachableRotation(BlockPos pos, Vec3d offset) { - Tuple rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), + protected static Optional reachableRotation(BlockPos pos, Vec3d offset) { + Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), offset); RayTraceResult result = raytraceTowards(rotation); if(result != null @@ -88,8 +89,8 @@ public final class LookBehaviorUtils implements Helper{ * @param pos * @return */ - protected static Optional> reachableCenter(BlockPos pos) { - Tuple rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), + protected static Optional reachableCenter(BlockPos pos) { + Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), Utils.calcCenterFromCoords(pos, mc.world)); RayTraceResult result = raytraceTowards(rotation); if(result != null diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java index 4148519e..1e57639b 100644 --- a/src/main/java/baritone/bot/pathing/movement/Movement.java +++ b/src/main/java/baritone/bot/pathing/movement/Movement.java @@ -7,7 +7,7 @@ import baritone.bot.pathing.movement.MovementState.MovementStatus; import baritone.bot.utils.BlockStateInterface; import baritone.bot.utils.Helper; import baritone.bot.utils.ToolSet; -import net.minecraft.util.Tuple; +import baritone.bot.utils.*; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -132,12 +132,11 @@ public abstract class Movement implements Helper, MovementHelper { if (state.getStatus() == MovementStatus.WAITING) { return true; } - Optional cruftPos; - for (BlockPos blockPos : positionsToBreak) { - if (MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) { - Optional> reachable = LookBehaviorUtils.reachable(blockPos); + for(BlockPos blockPos : positionsToBreak) { + if(MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) { + Optional reachable = LookBehaviorUtils.reachable(blockPos); reachable.ifPresent(rotation -> { - state.setTarget(new MovementState.MovementTarget()) + state.setTarget(new MovementState.MovementTarget(Optional.empty(), reachable)); state.setInput(Input.CLICK_LEFT, true); }); if (reachable.isPresent()) diff --git a/src/main/java/baritone/bot/pathing/movement/MovementState.java b/src/main/java/baritone/bot/pathing/movement/MovementState.java index e5aebed9..46ae3ba5 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementState.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementState.java @@ -39,9 +39,9 @@ public class MovementState { */ public Optional rotation; - public MovementTarget(Vec3d position, Rotation rotation) { - this.position = Optional.of(position); - this.rotation = Optional.of(rotation); + public MovementTarget(Optional position, Optional rotation) { + this.position = position; + this.rotation = rotation; } } diff --git a/src/main/java/baritone/bot/utils/Utils.java b/src/main/java/baritone/bot/utils/Utils.java index c919f0d1..6e62f1bf 100755 --- a/src/main/java/baritone/bot/utils/Utils.java +++ b/src/main/java/baritone/bot/utils/Utils.java @@ -25,11 +25,11 @@ public final class Utils { * @param dest * @return Rotation Tuple {@link LookBehavior#target} */ - public static Tuple calcRotationFromVec3d(Vec3d orig, Vec3d dest) { + public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) { double yaw = Math.atan2(orig.x - dest.x, -orig.z + dest.z); double dist = Math.sqrt((orig.x - dest.x) * (orig.x - dest.x) + (-orig.z + dest.z) * (-orig.z + dest.z)); double pitch = Math.atan2(orig.y - dest.y, dist); - return new Tuple<>((float) (yaw * 180 / Math.PI), + return new Rotation((float) (yaw * 180 / Math.PI), (float) (pitch * 180 / Math.PI)); }