Refactor moveTowards to be more stateful
This commit is contained in:
parent
174f84da73
commit
18431d78e3
@ -236,9 +236,4 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
toPlaceCached = result;
|
toPlaceCached = result;
|
||||||
return 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
package baritone.bot.pathing.movement;
|
package baritone.bot.pathing.movement;
|
||||||
|
|
||||||
|
import baritone.bot.InputOverrideHandler;
|
||||||
import baritone.bot.behavior.impl.LookBehaviorUtils;
|
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.MovementDescend;
|
||||||
import baritone.bot.pathing.movement.movements.MovementFall;
|
import baritone.bot.pathing.movement.movements.MovementFall;
|
||||||
import baritone.bot.utils.BlockStateInterface;
|
import baritone.bot.utils.*;
|
||||||
import baritone.bot.utils.Helper;
|
|
||||||
import baritone.bot.utils.ToolSet;
|
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@ -35,6 +35,7 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -201,6 +202,13 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return false;
|
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) {
|
static Movement generateMovementFallOrDescend(BlockPos pos, EnumFacing direction) {
|
||||||
BlockPos dest = pos.offset(direction);
|
BlockPos dest = pos.offset(direction);
|
||||||
BlockPos destUp = dest.up();
|
BlockPos destUp = dest.up();
|
||||||
|
@ -93,7 +93,7 @@ public class MovementAscend extends Movement {
|
|||||||
state.setStatus(MovementStatus.SUCCESS);
|
state.setStatus(MovementStatus.SUCCESS);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
moveTowards(positionsToBreak[0]);
|
MovementHelper.moveTowards(state, positionsToBreak[0]);
|
||||||
return state.setInput(InputOverrideHandler.Input.JUMP, true);
|
return state.setInput(InputOverrideHandler.Input.JUMP, true);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
@ -75,7 +75,7 @@ public class MovementDescend extends Movement {
|
|||||||
double diffZ2 = player().posZ - (fakeDest.getZ() + 0.5);
|
double diffZ2 = player().posZ - (fakeDest.getZ() + 0.5);
|
||||||
double d = Math.sqrt(diffX2 * diffX2 + diffZ2 * diffZ2);
|
double d = Math.sqrt(diffX2 * diffX2 + diffZ2 * diffZ2);
|
||||||
if (d > ab)
|
if (d > ab)
|
||||||
moveTowards(fakeDest);
|
MovementHelper.moveTowards(state, fakeDest);
|
||||||
else {
|
else {
|
||||||
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, false);
|
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, false);
|
||||||
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
|
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
|
||||||
|
@ -58,7 +58,7 @@ public class MovementDiagonal extends Movement {
|
|||||||
state.setStatus(MovementState.MovementStatus.SUCCESS);
|
state.setStatus(MovementState.MovementStatus.SUCCESS);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
moveTowards(dest);
|
MovementHelper.moveTowards(state, dest);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class MovementDownward extends Movement {
|
|||||||
if (numTicks++ < 10 && ab < 0.2) {
|
if (numTicks++ < 10 && ab < 0.2) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
moveTowards(positionsToBreak[0]);
|
MovementHelper.moveTowards(state, positionsToBreak[0]);
|
||||||
return state;
|
return state;
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
@ -133,7 +133,7 @@ public class MovementTraverse extends Movement {
|
|||||||
if (wasTheBridgeBlockAlwaysThere) {
|
if (wasTheBridgeBlockAlwaysThere) {
|
||||||
// player().setSprinting(true);
|
// player().setSprinting(true);
|
||||||
}
|
}
|
||||||
moveTowards(positionsToBreak[0]);
|
MovementHelper.moveTowards(state, positionsToBreak[0]);
|
||||||
return state;
|
return state;
|
||||||
} else {
|
} else {
|
||||||
wasTheBridgeBlockAlwaysThere = false;
|
wasTheBridgeBlockAlwaysThere = false;
|
||||||
@ -185,7 +185,7 @@ public class MovementTraverse extends Movement {
|
|||||||
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||||
return state;
|
return state;
|
||||||
} else {
|
} else {
|
||||||
moveTowards(positionsToBreak[0]);
|
MovementHelper.moveTowards(state, positionsToBreak[0]);
|
||||||
return state;
|
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
|
// 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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user