baritone/src/main/java/baritone/pathing/movement/MovementState.java

134 lines
3.7 KiB
Java
Raw Normal View History

2018-08-08 03:16:53 +00:00
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
2018-08-08 03:16:53 +00:00
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
2018-08-08 03:16:53 +00:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
2018-08-08 03:16:53 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
2018-08-08 03:16:53 +00:00
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
2018-08-22 20:15:56 +00:00
package baritone.pathing.movement;
2018-08-02 08:15:51 +00:00
2018-08-22 20:15:56 +00:00
import baritone.utils.InputOverrideHandler.Input;
import baritone.utils.Rotation;
2018-08-02 14:59:51 +00:00
import net.minecraft.util.math.Vec3d;
2018-08-02 08:15:51 +00:00
2018-08-02 13:20:35 +00:00
import java.util.HashMap;
2018-08-02 08:15:51 +00:00
import java.util.Map;
2018-08-06 00:37:42 +00:00
import java.util.Optional;
2018-08-02 08:15:51 +00:00
2018-08-02 21:28:35 +00:00
public class MovementState {
2018-08-02 08:15:51 +00:00
2018-08-04 18:49:52 +00:00
private MovementStatus status;
2018-08-06 04:42:17 +00:00
private MovementTarget goal = new MovementTarget();
private MovementTarget target = new MovementTarget();
private final Map<Input, Boolean> inputState = new HashMap<>();
2018-08-02 08:15:51 +00:00
2018-08-02 21:28:35 +00:00
public MovementState setStatus(MovementStatus status) {
2018-08-02 08:15:51 +00:00
this.status = status;
return this;
}
2018-08-02 21:28:35 +00:00
public MovementStatus getStatus() {
2018-08-02 08:15:51 +00:00
return status;
}
public MovementTarget getGoal() {
return this.goal;
}
public MovementState setGoal(MovementTarget goal) {
this.goal = goal;
return this;
}
public MovementTarget getTarget() {
return this.target;
}
public MovementState setTarget(MovementTarget target) {
this.target = target;
return this;
}
public MovementState setInput(Input input, boolean forced) {
this.inputState.put(input, forced);
return this;
}
public boolean getInput(Input input) {
return this.inputState.getOrDefault(input, false);
}
public Map<Input, Boolean> getInputStates() {
return this.inputState;
}
public enum MovementStatus {
PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED, CANCELED
}
2018-08-06 00:37:42 +00:00
public static class MovementTarget {
2018-08-02 08:15:51 +00:00
/**
* Necessary movement to achieve
* <p>
* TODO: Decide desiredMovement type
*/
2018-08-06 04:42:17 +00:00
public Vec3d position;
2018-08-02 08:15:51 +00:00
/**
* Yaw and pitch angles that must be matched
* <p>
* getFirst() -> YAW
* getSecond() -> PITCH
*/
2018-08-06 04:42:17 +00:00
public Rotation rotation;
2018-08-02 08:15:51 +00:00
/**
* Whether or not this target must force rotations.
* <p>
* {@code true} if we're trying to place or break blocks, {@code false} if we're trying to look at the movement location
*/
private boolean forceRotations;
2018-08-06 04:42:17 +00:00
public MovementTarget() {
this(null, null, false);
2018-08-06 04:42:17 +00:00
}
public MovementTarget(Vec3d position) {
this(position, null, false);
2018-08-06 04:42:17 +00:00
}
public MovementTarget(Rotation rotation, boolean forceRotations) {
this(null, rotation, forceRotations);
2018-08-06 04:42:17 +00:00
}
public MovementTarget(Vec3d position, Rotation rotation, boolean forceRotations) {
this.position = position;
this.rotation = rotation;
this.forceRotations = forceRotations;
2018-08-02 08:15:51 +00:00
}
2018-08-06 04:42:17 +00:00
public final Optional<Vec3d> getPosition() {
return Optional.ofNullable(this.position);
2018-08-06 04:42:17 +00:00
}
public final Optional<Rotation> getRotation() {
return Optional.ofNullable(this.rotation);
2018-08-06 04:42:17 +00:00
}
public boolean hasToForceRotations() {
return this.forceRotations;
}
2018-08-02 08:15:51 +00:00
}
}