Fix target creation of Movement superclass

This commit is contained in:
Howard Stark 2018-08-05 20:50:59 -04:00
parent 84aeca710e
commit 3c6415d486
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
4 changed files with 16 additions and 16 deletions

View File

@ -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<Tuple<Float, Float>> reachable(BlockPos pos) {
public static Optional<Rotation> 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<Tuple<Float, Float>> reachableRotation(BlockPos pos, Vec3d offset) {
Tuple<Float, Float> rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
protected static Optional<Rotation> 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<Tuple<Float, Float>> reachableCenter(BlockPos pos) {
Tuple<Float, Float> rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
protected static Optional<Rotation> reachableCenter(BlockPos pos) {
Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
Utils.calcCenterFromCoords(pos, mc.world));
RayTraceResult result = raytraceTowards(rotation);
if(result != null

View File

@ -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<BlockPos> cruftPos;
for (BlockPos blockPos : positionsToBreak) {
if (MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
Optional<Tuple<Float, Float>> reachable = LookBehaviorUtils.reachable(blockPos);
for(BlockPos blockPos : positionsToBreak) {
if(MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
Optional<Rotation> 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())

View File

@ -39,9 +39,9 @@ public class MovementState {
*/
public Optional<Rotation> rotation;
public MovementTarget(Vec3d position, Rotation rotation) {
this.position = Optional.of(position);
this.rotation = Optional.of(rotation);
public MovementTarget(Optional<Vec3d> position, Optional<Rotation> rotation) {
this.position = position;
this.rotation = rotation;
}
}

View File

@ -25,11 +25,11 @@ public final class Utils {
* @param dest
* @return Rotation Tuple {@link LookBehavior#target}
*/
public static Tuple<Float, Float> 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));
}