Small changes

This commit is contained in:
Howard Stark 2018-08-04 14:49:52 -04:00
parent 13f9e169f0
commit d36b254ccc
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
5 changed files with 82 additions and 48 deletions

View 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();
}

View File

@ -1,7 +1,6 @@
package baritone.bot.pathing.movement; package baritone.bot.pathing.movement;
import baritone.bot.Baritone; import baritone.bot.Baritone;
import baritone.bot.event.AbstractGameEventListener;
import baritone.bot.pathing.movement.MovementState.MovementStatus; import baritone.bot.pathing.movement.MovementState.MovementStatus;
import baritone.bot.utils.Helper; import baritone.bot.utils.Helper;
import baritone.bot.utils.ToolSet; import baritone.bot.utils.ToolSet;
@ -12,10 +11,9 @@ import net.minecraft.util.math.Vec3d;
import java.util.Optional; import java.util.Optional;
public abstract class Movement implements AbstractGameEventListener, Helper, MovementHelper { public abstract class Movement implements IMovement, Helper, MovementHelper {
protected MovementState currentState;
protected MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
protected final BlockPos src; protected final BlockPos src;
protected final BlockPos dest; 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) { protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace, Vec3d rotationTarget) {
this(src, dest, toBreak, toPlace); this(src, dest, toBreak, toPlace);
currentState = new MovementState() // currentState = new MovementState()
.setLookDirection(rotationTarget) // .setGoal(new )
.setStatus(MovementStatus.WAITING); // .setStatus(MovementStatus.WAITING);
} }
public abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks public abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks
@Override public MovementStatus update() {
public void onTick() { if(isPrepared(state)) {
MovementState latestState = updateState(); if (!currentState.isPresent()) {
Optional<Vec3d> orientation = latestState.getGoal().rotation; currentState = Optional.of(new MovementState()
if (orientation.isPresent()) { .setStatus(MovementStatus.WAITING)
Tuple<Float, Float> rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), .setGoal());
orientation.get()); }
mc.player.setPositionAndRotation(mc.player.posX, mc.player.posY, mc.player.posZ,
rotation.getFirst(), rotation.getSecond());
} }
if(isFinished()) {
}
MovementState latestState = updateState();
Tuple<Float, Float> rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
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 //TODO calculate movement inputs from latestState.getGoal().position
latestState.inputState.forEach((input, forced) -> { latestState.inputState.forEach((input, forced) -> {
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced); Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
@ -67,6 +71,13 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov
return; return;
} }
private boolean prepare(MovementState state) {
Optional<BlockPos> cruftPos;
for(BlockPos blockPos : positionsToBreak) {
world().getBlockState(blockPos).getBlock()(world())
}
}
public boolean isFinished() { public boolean isFinished() {
return (currentState.getStatus() != MovementStatus.RUNNING return (currentState.getStatus() != MovementStatus.RUNNING
&& currentState.getStatus() != MovementStatus.WAITING); && currentState.getStatus() != MovementStatus.WAITING);
@ -91,5 +102,9 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov
* *
* @return * @return
*/ */
public abstract MovementState updateState(); public MovementState updateState(MovementState state) {
if(!prepare(state))
return state.setStatus(MovementStatus.PREPPING);
return state;
}
} }

View File

@ -5,14 +5,15 @@ import net.minecraft.util.math.Vec3d;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class MovementState { public class MovementState {
protected MovementStatus status; private MovementStatus status;
public MovementGoal goal = new MovementGoal(); private MovementGoal goal;
protected final Map<Input, Boolean> inputState = new HashMap<>(); protected final Map<Input, Boolean> inputState = new HashMap<>();
private Vec3d interme;
public MovementState setStatus(MovementStatus status) { public MovementState setStatus(MovementStatus status) {
this.status = status; this.status = status;
return this; return this;
@ -28,18 +29,18 @@ public class MovementState {
* <p> * <p>
* TODO: Decide desiredMovement type * TODO: Decide desiredMovement type
*/ */
public Optional<Vec3d> position; public Vec3d position;
/** /**
* Yaw and pitch angles that must be matched * Yaw and pitch angles that must be matched
* <p> * <p>
* getFirst() -> YAW * getFirst() -> YAW
* getSecond() -> PITCH * getSecond() -> PITCH
*/ */
public Optional<Vec3d> rotation; public Vec3d rotation;
public MovementGoal() { public MovementGoal(Vec3d position, Vec3d rotation) {
this.position = Optional.empty(); this.position = position;
this.rotation = Optional.empty(); this.rotation = rotation;
} }
} }
@ -47,23 +48,8 @@ public class MovementState {
return goal; return goal;
} }
public MovementState setPosition(Vec3d posGoal) { public MovementState setGoal(MovementGoal goal) {
this.goal.position = Optional.of(posGoal); this.goal = goal;
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();
return this; return this;
} }
@ -77,6 +63,6 @@ public class MovementState {
} }
public enum MovementStatus { public enum MovementStatus {
WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED; PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED;
} }
} }

View File

@ -3,6 +3,7 @@ package baritone.bot.pathing.movement.movements;
import baritone.bot.InputOverrideHandler; import baritone.bot.InputOverrideHandler;
import baritone.bot.pathing.movement.Movement; import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.MovementState; import baritone.bot.pathing.movement.MovementState;
import baritone.bot.pathing.movement.MovementState.MovementStatus;
import baritone.bot.utils.ToolSet; import baritone.bot.utils.ToolSet;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -23,10 +24,20 @@ public class MovementAscend extends Movement {
} }
@Override @Override
public MovementState updateState() { public MovementState updateState(MovementState state) {
MovementState latestState = currentState.setInput(InputOverrideHandler.Input.JUMP, true).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); super.updateState(state);
if (playerFeet().equals(dest)) switch(state.getStatus()) {
latestState.setStatus(MovementState.MovementStatus.SUCCESS); case PREPPING:
return latestState; 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(MovementStatus.SUCCESS);
default:
return state;
}
} }
} }

View File

@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/** /**
* @author Brady * @author Brady
@ -13,6 +14,14 @@ public interface Helper {
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = Minecraft.getMinecraft();
default EntityPlayerSP player() {
return mc.player;
}
default World world() {
return mc.world;
}
default BlockPos playerFeet() { default BlockPos playerFeet() {
return new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ); return new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ);
} }