Refactor moveTowards to be more stateful

This commit is contained in:
Howard Stark 2018-08-08 12:51:04 -07:00
parent 174f84da73
commit 18431d78e3
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
7 changed files with 17 additions and 14 deletions

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -58,7 +58,7 @@ public class MovementDiagonal extends Movement {
state.setStatus(MovementState.MovementStatus.SUCCESS);
return state;
}
moveTowards(dest);
MovementHelper.moveTowards(state, dest);
return state;
}

View File

@ -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;

View File

@ -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
}