Small changes
This commit is contained in:
parent
13f9e169f0
commit
d36b254ccc
13
src/main/java/baritone/bot/pathing/movement/IMovement.java
Normal file
13
src/main/java/baritone/bot/pathing/movement/IMovement.java
Normal file
@ -0,0 +1,13 @@
|
||||
package baritone.bot.pathing.movement;
|
||||
|
||||
public interface IMovement {
|
||||
|
||||
/**
|
||||
* Handles the execution of the latest Movement
|
||||
* State, and offers a Status to the calling class.
|
||||
*
|
||||
* @return Status
|
||||
*/
|
||||
MovementState.MovementStatus update();
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package baritone.bot.pathing.movement;
|
||||
|
||||
import baritone.bot.Baritone;
|
||||
import baritone.bot.event.AbstractGameEventListener;
|
||||
import baritone.bot.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.bot.utils.Helper;
|
||||
import baritone.bot.utils.ToolSet;
|
||||
@ -12,10 +11,9 @@ import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class Movement implements AbstractGameEventListener, Helper, MovementHelper {
|
||||
|
||||
protected MovementState currentState;
|
||||
public abstract class Movement implements IMovement, Helper, MovementHelper {
|
||||
|
||||
protected MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
||||
protected final BlockPos src;
|
||||
|
||||
protected final BlockPos dest;
|
||||
@ -39,23 +37,29 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov
|
||||
|
||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace, Vec3d rotationTarget) {
|
||||
this(src, dest, toBreak, toPlace);
|
||||
currentState = new MovementState()
|
||||
.setLookDirection(rotationTarget)
|
||||
.setStatus(MovementStatus.WAITING);
|
||||
// currentState = new MovementState()
|
||||
// .setGoal(new )
|
||||
// .setStatus(MovementStatus.WAITING);
|
||||
}
|
||||
|
||||
public abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
public MovementStatus update() {
|
||||
if(isPrepared(state)) {
|
||||
if (!currentState.isPresent()) {
|
||||
currentState = Optional.of(new MovementState()
|
||||
.setStatus(MovementStatus.WAITING)
|
||||
.setGoal());
|
||||
}
|
||||
}
|
||||
if(isFinished()) {
|
||||
|
||||
}
|
||||
MovementState latestState = updateState();
|
||||
Optional<Vec3d> orientation = latestState.getGoal().rotation;
|
||||
if (orientation.isPresent()) {
|
||||
Tuple<Float, Float> rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
||||
orientation.get());
|
||||
latestState.getGoal().rotation);
|
||||
mc.player.setPositionAndRotation(mc.player.posX, mc.player.posY, mc.player.posZ,
|
||||
rotation.getFirst(), rotation.getSecond());
|
||||
}
|
||||
//TODO calculate movement inputs from latestState.getGoal().position
|
||||
latestState.inputState.forEach((input, forced) -> {
|
||||
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
||||
@ -67,6 +71,13 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov
|
||||
return;
|
||||
}
|
||||
|
||||
private boolean prepare(MovementState state) {
|
||||
Optional<BlockPos> cruftPos;
|
||||
for(BlockPos blockPos : positionsToBreak) {
|
||||
world().getBlockState(blockPos).getBlock()(world())
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return (currentState.getStatus() != MovementStatus.RUNNING
|
||||
&& currentState.getStatus() != MovementStatus.WAITING);
|
||||
@ -91,5 +102,9 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract MovementState updateState();
|
||||
public MovementState updateState(MovementState state) {
|
||||
if(!prepare(state))
|
||||
return state.setStatus(MovementStatus.PREPPING);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,15 @@ import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MovementState {
|
||||
|
||||
protected MovementStatus status;
|
||||
public MovementGoal goal = new MovementGoal();
|
||||
private MovementStatus status;
|
||||
private MovementGoal goal;
|
||||
protected final Map<Input, Boolean> inputState = new HashMap<>();
|
||||
|
||||
private Vec3d interme;
|
||||
|
||||
public MovementState setStatus(MovementStatus status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
@ -28,18 +29,18 @@ public class MovementState {
|
||||
* <p>
|
||||
* TODO: Decide desiredMovement type
|
||||
*/
|
||||
public Optional<Vec3d> position;
|
||||
public Vec3d position;
|
||||
/**
|
||||
* Yaw and pitch angles that must be matched
|
||||
* <p>
|
||||
* getFirst() -> YAW
|
||||
* getSecond() -> PITCH
|
||||
*/
|
||||
public Optional<Vec3d> rotation;
|
||||
public Vec3d rotation;
|
||||
|
||||
public MovementGoal() {
|
||||
this.position = Optional.empty();
|
||||
this.rotation = Optional.empty();
|
||||
public MovementGoal(Vec3d position, Vec3d rotation) {
|
||||
this.position = position;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,23 +48,8 @@ public class MovementState {
|
||||
return goal;
|
||||
}
|
||||
|
||||
public MovementState setPosition(Vec3d posGoal) {
|
||||
this.goal.position = Optional.of(posGoal);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MovementState clearPosition() {
|
||||
this.goal.position = Optional.empty();
|
||||
return this;
|
||||
}
|
||||
|
||||
public MovementState setLookDirection(Vec3d rotGoal) {
|
||||
this.goal.rotation = Optional.of(rotGoal);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MovementState clearLookDirection() {
|
||||
this.goal.rotation = Optional.empty();
|
||||
public MovementState setGoal(MovementGoal goal) {
|
||||
this.goal = goal;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -77,6 +63,6 @@ public class MovementState {
|
||||
}
|
||||
|
||||
public enum MovementStatus {
|
||||
WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED;
|
||||
PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package baritone.bot.pathing.movement.movements;
|
||||
import baritone.bot.InputOverrideHandler;
|
||||
import baritone.bot.pathing.movement.Movement;
|
||||
import baritone.bot.pathing.movement.MovementState;
|
||||
import baritone.bot.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.bot.utils.ToolSet;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@ -23,10 +24,20 @@ public class MovementAscend extends Movement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MovementState updateState() {
|
||||
public MovementState updateState(MovementState state) {
|
||||
super.updateState(state);
|
||||
switch(state.getStatus()) {
|
||||
case PREPPING:
|
||||
case UNREACHABLE:
|
||||
case FAILED:
|
||||
return state;
|
||||
case WAITING:
|
||||
case RUNNING:
|
||||
MovementState latestState = currentState.setInput(InputOverrideHandler.Input.JUMP, true).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
if (playerFeet().equals(dest))
|
||||
latestState.setStatus(MovementState.MovementStatus.SUCCESS);
|
||||
return latestState;
|
||||
latestState.setStatus(MovementStatus.SUCCESS);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@ -13,6 +14,14 @@ public interface Helper {
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
default EntityPlayerSP player() {
|
||||
return mc.player;
|
||||
}
|
||||
|
||||
default World world() {
|
||||
return mc.world;
|
||||
}
|
||||
|
||||
default BlockPos playerFeet() {
|
||||
return new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user