Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions src/main/java/baritone/bot/pathing/movement/Movement.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,22 @@ public double recalculateCost() {
*/
public MovementStatus update() {
player().setSprinting(false);
MovementState latestState = updateState(currentState);
switch (currentState.getStatus()) {
case PREPPING:
onPrepping(currentState);
break;
case WAITING:
case RUNNING:
onRunning(currentState);
break;
case SUCCESS:
case FAILED:
case CANCELED:
case UNREACHABLE:
onFinished(currentState);
break;
}
MovementState latestState = currentState;
if (BlockStateInterface.isLiquid(playerFeet())) {
latestState.setInput(Input.JUMP, true);
}
Expand All @@ -118,15 +133,12 @@ public MovementStatus update() {
currentState = latestState;

if (isFinished())
onFinish(latestState);
onFinished(latestState);

return currentState.getStatus();
}

protected boolean prepared(MovementState state) {
if (state.getStatus() == MovementStatus.WAITING)
return true;

protected void onPrepping(MovementState state) {
boolean somethingInTheWay = false;
for (BlockPos blockPos : positionsToBreak) {
if (!MovementHelper.canWalkThrough(blockPos)) {
Expand All @@ -135,17 +147,25 @@ protected boolean prepared(MovementState state) {
if (reachable.isPresent()) {
player().inventory.currentItem = new ToolSet().getBestSlot(BlockStateInterface.get(blockPos));
state.setTarget(new MovementState.MovementTarget(reachable.get())).setInput(Input.CLICK_LEFT, true);
return false;
return; // still prepping
}
}
}
if (somethingInTheWay) {
// There's a block or blocks that we can't walk through, but we have no target rotation to reach any
// So don't return true, actually set state to unreachable
state.setStatus(MovementStatus.UNREACHABLE);
return true;
}
return true;
state.setStatus(MovementStatus.WAITING);
}

/**
* Once the Movement has been prepared and is ready to onRunning, do so
*
* @param state
*/
protected void onRunning(MovementState state) {

}

public boolean isFinished() {
Expand All @@ -165,7 +185,7 @@ public BlockPos getDest() {
/**
* Run cleanup on state finish and declare success.
*/
public void onFinish(MovementState state) {
public void onFinished(MovementState state) {
state.getInputStates().replaceAll((input, forced) -> false);
state.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
state.setStatus(MovementStatus.SUCCESS);
Expand Down Expand Up @@ -217,22 +237,6 @@ public double getTotalHardnessOfBlocksToBreak(ToolSet ts) {
return sum;
}


/**
* Calculate latest movement state.
* Gets called once a tick.
*
* @return
*/
public MovementState updateState(MovementState state) {
if (!prepared(state))
return state.setStatus(MovementStatus.PREPPING);
else if (state.getStatus() == MovementStatus.PREPPING) {
state.setStatus(MovementStatus.WAITING);
}
return state;
}

public ArrayList<BlockPos> toBreakCached = null;
public ArrayList<BlockPos> toPlaceCached = null;
public ArrayList<BlockPos> toWalkIntoCached = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package baritone.bot.pathing.movement.movements;

import baritone.bot.utils.InputOverrideHandler;
import baritone.bot.behavior.impl.LookBehaviorUtils;
import baritone.bot.pathing.movement.CalculationContext;
import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.MovementHelper;
import baritone.bot.pathing.movement.MovementState;
import baritone.bot.pathing.movement.MovementState.MovementStatus;
import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.InputOverrideHandler;
import baritone.bot.utils.Utils;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -93,31 +93,19 @@ protected double calculateCost(CalculationContext context) {
}

@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
public void onRunning(MovementState state) {
// TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
switch (state.getStatus()) {
case PREPPING:
case UNREACHABLE:
case FAILED:
return state;
case WAITING:
case RUNNING:
break;
default:
return state;
}
if (playerFeet().equals(dest)) {
state.setStatus(MovementStatus.SUCCESS);
return state;
return;
}

if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
for (BlockPos anAgainst : against) {
if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) {
if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block
return state.setStatus(MovementStatus.UNREACHABLE);
state.setStatus(MovementStatus.UNREACHABLE);
return;
}
double faceX = (dest.getX() + anAgainst.getX() + 1.0D) * 0.5D;
double faceY = (dest.getY() + anAgainst.getY()) * 0.5D;
Expand All @@ -135,14 +123,14 @@ public MovementState updateState(MovementState state) {
}
}
System.out.println("Trying to look at " + anAgainst + ", actually looking at" + LookBehaviorUtils.getSelectedBlock());
return state;
return;
}
}
return state.setStatus(MovementStatus.UNREACHABLE);
state.setStatus(MovementStatus.UNREACHABLE);
return;
}
MovementHelper.moveTowards(state, dest);
state.setInput(InputOverrideHandler.Input.JUMP, true);

// TODO check if the below actually helps or hurts, it's weird
//double flatDistToNext = Math.abs(to.getX() - from.getX()) * Math.abs((to.getX() + 0.5D) - thePlayer.posX) + Math.abs(to.getZ() - from.getZ()) * Math.abs((to.getZ() + 0.5D) - thePlayer.posZ);
//boolean pointingInCorrectDirection = MovementManager.moveTowardsBlock(to);
Expand All @@ -151,7 +139,5 @@ public MovementState updateState(MovementState state) {
//this is slightly more efficient because otherwise we might start jumping before moving, and fall down without moving onto the block we want to jump onto
//also wait until we are close enough, because we might jump and hit our head on an adjacent block
//return Baritone.playerFeet.equals(to);

return state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

package baritone.bot.pathing.movement.movements;

import baritone.bot.utils.InputOverrideHandler;
import baritone.bot.pathing.movement.CalculationContext;
import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.MovementHelper;
import baritone.bot.pathing.movement.MovementState;
import baritone.bot.pathing.movement.MovementState.MovementStatus;
import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.InputOverrideHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
Expand Down Expand Up @@ -56,26 +56,13 @@ protected double calculateCost(CalculationContext context) {
int numTicks = 0;

@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
switch (state.getStatus()) {
case PREPPING:
case UNREACHABLE:
case FAILED:
return state;
case WAITING:
state.setStatus(MovementStatus.RUNNING);
case RUNNING:
break;
default:
return state;
}
public void onRunning(MovementState state) {
BlockPos playerFeet = playerFeet();
if (playerFeet.equals(dest)) {
if (BlockStateInterface.isLiquid(dest) || player().posY - playerFeet.getY() < 0.01) {
// Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
state.setStatus(MovementStatus.SUCCESS);
return state;
return;
} else {
System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY()));
}
Expand All @@ -101,6 +88,5 @@ public MovementState updateState(MovementState state) {
MovementHelper.moveTowards(state, dest);
}
}
return state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,15 @@ public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos di
}

@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
switch (state.getStatus()) {
case PREPPING:
case UNREACHABLE:
case FAILED:
return state;
case WAITING:
case RUNNING:
break;
default:
return state;
}
public void onRunning(MovementState state) {
if (playerFeet().equals(dest)) {
state.setStatus(MovementState.MovementStatus.SUCCESS);
return state;
return;
}
if (!BlockStateInterface.isLiquid(playerFeet())) {
player().setSprinting(true);
}
MovementHelper.moveTowards(state, dest);
return state;
}

@Override
Expand Down Expand Up @@ -129,8 +116,8 @@ protected double calculateCost(CalculationContext context) {
}

@Override
protected boolean prepared(MovementState state) {
return true;
protected void onPrepping(MovementState state) {
state.setStatus(MovementState.MovementStatus.RUNNING);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,18 @@ protected double calculateCost(CalculationContext context) {
}

@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
switch (state.getStatus()) {
case PREPPING:
case UNREACHABLE:
case FAILED:
return state;
case WAITING:
case RUNNING:
break;
default:
return state;
}
public void onRunning(MovementState state) {
if (playerFeet().equals(dest)) {
state.setStatus(MovementState.MovementStatus.SUCCESS);
return state;
return;
}
double diffX = player().posX - (dest.getX() + 0.5);
double diffZ = player().posZ - (dest.getZ() + 0.5);
double ab = Math.sqrt(diffX * diffX + diffZ * diffZ);

if (numTicks++ < 10 && ab < 0.2) {
return state;
return;
}
MovementHelper.moveTowards(state, positionsToBreak[0]);
return state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package baritone.bot.pathing.movement.movements;

import baritone.bot.utils.InputOverrideHandler;
import baritone.bot.behavior.impl.LookBehaviorUtils;
import baritone.bot.pathing.movement.*;
import baritone.bot.pathing.movement.MovementState.MovementStatus;
import baritone.bot.pathing.movement.MovementState.MovementTarget;
import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.InputOverrideHandler;
import baritone.bot.utils.Rotation;
import baritone.bot.utils.Utils;
import net.minecraft.init.Items;
Expand Down Expand Up @@ -64,26 +64,13 @@ protected double calculateCost(CalculationContext context) {
}

@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
switch (state.getStatus()) {
case PREPPING:
case UNREACHABLE:
case FAILED:
return state;
case WAITING:
state.setStatus(MovementStatus.RUNNING);
case RUNNING:
break;
default:
return state;
}
public void onRunning(MovementState state) {
BlockPos playerFeet = playerFeet();
Optional<Rotation> targetRotation = Optional.empty();
if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3 && !playerFeet.equals(dest)) {
if (!player().inventory.hasItemStack(STACK_BUCKET_WATER) || world().provider.isNether()) { // TODO check if water bucket is on hotbar or main inventory
state.setStatus(MovementStatus.UNREACHABLE);
return state;
return;
}
if (player().posY - dest.getY() < mc.playerController.getBlockReachDistance()) {
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_WATER);
Expand All @@ -101,18 +88,17 @@ public MovementState updateState(MovementState state) {
if (BlockStateInterface.isWater(dest) && player().inventory.hasItemStack(STACK_BUCKET_EMPTY)) {
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
if (player().motionY >= 0) {
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
} else {
return state;
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
}
return;
}
return state.setStatus(MovementStatus.SUCCESS);
state.setStatus(MovementStatus.SUCCESS);
return;
}
Vec3d destCenter = Utils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}
return state;
}

private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {
Expand Down
Loading