2018-08-02 21:28:35 +00:00
|
|
|
package baritone.bot.pathing.movement;
|
2018-08-02 04:07:55 +00:00
|
|
|
|
2018-08-02 08:15:51 +00:00
|
|
|
import baritone.bot.Baritone;
|
2018-08-02 14:59:51 +00:00
|
|
|
import baritone.bot.event.AbstractGameEventListener;
|
2018-08-02 21:28:35 +00:00
|
|
|
import baritone.bot.pathing.movement.MovementState.MovementStatus;
|
2018-08-02 14:59:51 +00:00
|
|
|
import baritone.bot.utils.Helper;
|
2018-08-02 22:35:36 +00:00
|
|
|
import baritone.bot.utils.ToolSet;
|
2018-08-02 07:12:51 +00:00
|
|
|
import baritone.bot.utils.Utils;
|
|
|
|
import net.minecraft.util.Tuple;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-08-02 14:59:51 +00:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2018-08-02 07:12:51 +00:00
|
|
|
|
2018-08-02 22:35:36 +00:00
|
|
|
import java.util.Optional;
|
|
|
|
|
2018-08-02 21:28:35 +00:00
|
|
|
public abstract class Movement implements AbstractGameEventListener, Helper, MovementHelper {
|
2018-08-02 07:12:51 +00:00
|
|
|
|
2018-08-02 21:28:35 +00:00
|
|
|
protected MovementState currentState;
|
2018-08-02 18:12:56 +00:00
|
|
|
protected final BlockPos src;
|
|
|
|
protected final BlockPos dest;
|
2018-08-03 03:30:35 +00:00
|
|
|
/**
|
|
|
|
* The positions that need to be broken before this movement can ensue
|
|
|
|
*/
|
|
|
|
public final BlockPos[] positionsToBreak;
|
|
|
|
/**
|
|
|
|
* The positions where we need to place a block before this movement can ensue
|
|
|
|
*/
|
|
|
|
public final BlockPos[] positionsToPlace;
|
2018-08-02 07:12:51 +00:00
|
|
|
|
2018-08-03 03:30:35 +00:00
|
|
|
|
|
|
|
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace) {
|
2018-08-02 22:35:36 +00:00
|
|
|
this.src = src;
|
|
|
|
this.dest = dest;
|
2018-08-03 03:30:35 +00:00
|
|
|
this.positionsToBreak = toBreak;
|
|
|
|
this.positionsToPlace = toPlace;
|
2018-08-02 14:59:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 03:30:35 +00:00
|
|
|
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace, Vec3d rotationTarget) {
|
|
|
|
this(src, dest, toBreak, toPlace);
|
2018-08-02 21:28:35 +00:00
|
|
|
currentState = new MovementState()
|
2018-08-02 22:35:36 +00:00
|
|
|
.setLookDirection(rotationTarget)
|
2018-08-02 21:28:35 +00:00
|
|
|
.setStatus(MovementStatus.WAITING);
|
2018-08-02 07:12:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 22:35:36 +00:00
|
|
|
public abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks
|
2018-08-02 07:12:51 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTick() {
|
2018-08-03 03:40:27 +00:00
|
|
|
MovementState latestState = updateState();
|
2018-08-02 22:35:36 +00:00
|
|
|
Optional<Vec3d> orientation = latestState.getGoal().rotation;
|
|
|
|
if (orientation.isPresent()) {
|
|
|
|
Tuple<Float, Float> rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
|
|
|
orientation.get());
|
|
|
|
mc.player.setPositionAndRotation(mc.player.posX, mc.player.posY, mc.player.posZ,
|
|
|
|
rotation.getFirst(), rotation.getSecond());
|
|
|
|
}
|
|
|
|
//TODO calculate movement inputs from latestState.getGoal().position
|
2018-08-02 08:15:51 +00:00
|
|
|
latestState.inputState.forEach((input, forced) -> {
|
|
|
|
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
|
|
|
});
|
|
|
|
currentState = latestState;
|
|
|
|
|
2018-08-02 14:01:34 +00:00
|
|
|
if (isFinished())
|
2018-08-03 03:40:27 +00:00
|
|
|
onFinish();
|
2018-08-02 08:15:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFinished() {
|
2018-08-02 21:28:35 +00:00
|
|
|
return (currentState.getStatus() != MovementStatus.RUNNING
|
|
|
|
&& currentState.getStatus() != MovementStatus.WAITING);
|
2018-08-02 07:12:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 18:05:47 +00:00
|
|
|
public BlockPos getSrc() {
|
2018-08-02 18:12:56 +00:00
|
|
|
return src;
|
2018-08-02 18:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPos getDest() {
|
2018-08-02 18:12:56 +00:00
|
|
|
return dest;
|
2018-08-02 18:05:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 03:40:27 +00:00
|
|
|
/**
|
|
|
|
* Run cleanup on state finish
|
|
|
|
*/
|
|
|
|
public abstract void onFinish();
|
|
|
|
|
2018-08-02 07:12:51 +00:00
|
|
|
/**
|
2018-08-02 21:28:35 +00:00
|
|
|
* Calculate latest movement state.
|
2018-08-02 07:12:51 +00:00
|
|
|
* Gets called once a tick.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
2018-08-03 03:40:27 +00:00
|
|
|
public abstract MovementState updateState();
|
2018-08-02 04:07:55 +00:00
|
|
|
}
|