make elytra play nice with CustomGoalProcess

This commit is contained in:
Babbaj 2023-07-22 01:55:12 -04:00
parent 097e30850f
commit 664375a678
No known key found for this signature in database
GPG Key ID: F044309848A07CAC
6 changed files with 58 additions and 27 deletions

View File

@ -17,6 +17,7 @@
package baritone.api.process;
import baritone.api.pathing.goals.Goal;
import net.minecraft.util.math.BlockPos;
public interface IElytraProcess extends IBaritoneProcess {
@ -30,6 +31,8 @@ public interface IElytraProcess extends IBaritoneProcess {
void pathTo(BlockPos destination);
void pathTo(Goal destination);
/**
* Resets the state of the process but will maintain the same destination and will try to keep flying
*/

View File

@ -59,26 +59,11 @@ public class ElytraCommand extends Command {
if (iGoal == null) {
throw new CommandInvalidStateException("No goal has been set");
}
final int x;
final int y;
final int z;
if (iGoal instanceof GoalXZ) {
GoalXZ goal = (GoalXZ) iGoal;
x = goal.getX();
y = 64;
z = goal.getZ();
} else if (iGoal instanceof GoalBlock) {
GoalBlock goal = (GoalBlock) iGoal;
x = goal.x;
y = goal.y;
z = goal.z;
} else {
throw new CommandInvalidStateException("The goal must be a GoalXZ or GoalBlock");
try {
elytra.pathTo(iGoal);
} catch (IllegalArgumentException ex) {
throw new CommandInvalidStateException(ex.getMessage());
}
if (y <= 0 || y >= 128) {
throw new CommandInvalidStateException("The y of the goal is not between 0 and 128");
}
elytra.pathTo(new BlockPos(x, y, z));
return;
}

View File

@ -56,6 +56,9 @@ public final class CustomGoalProcess extends BaritoneProcessHelper implements IC
public void setGoal(Goal goal) {
this.goal = goal;
this.mostRecentGoal = goal;
if (baritone.getElytraProcess().isActive()) {
baritone.getElytraProcess().pathTo(goal);
}
if (this.state == State.NONE) {
this.state = State.GOAL_SET;
}

View File

@ -23,6 +23,8 @@ import baritone.api.event.events.*;
import baritone.api.event.events.type.EventState;
import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.pathing.goals.GoalYLevel;
import baritone.api.pathing.movement.IMovement;
import baritone.api.pathing.path.IPathExecutor;
@ -48,7 +50,6 @@ import net.minecraft.util.math.Vec3d;
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
public class ElytraProcess extends BaritoneProcessHelper implements IBaritoneProcess, IElytraProcess, AbstractGameEventListener {
public State state;
private Goal goal;
private LegacyElytraBehavior behavior;
@ -93,7 +94,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
if (ctx.player().isElytraFlying()) {
if (ctx.player().isElytraFlying() && this.state != State.LANDING) {
final BetterBlockPos last = behavior.pathManager.path.getLast();
if (last != null && ctx.player().getDistanceSqToCenter(last) < (5 * 5)) {
if (Baritone.settings().notificationOnPathComplete.value) {
@ -215,6 +216,11 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
}
}
@Override
public double priority() {
return 0; // higher priority than CustomGoalProcess
}
@Override
public String displayName0() {
return "Elytra - " + this.state.description;
@ -234,6 +240,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
@Override
public void pathTo(BlockPos destination) {
this.onLostControl();
this.behavior = new LegacyElytraBehavior(this.baritone, this, destination);
if (ctx.world() != null) {
this.behavior.repackChunks();
@ -241,6 +248,30 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
this.behavior.pathTo();
}
@Override
public void pathTo(Goal iGoal) {
final int x;
final int y;
final int z;
if (iGoal instanceof GoalXZ) {
GoalXZ goal = (GoalXZ) iGoal;
x = goal.getX();
y = 64;
z = goal.getZ();
} else if (iGoal instanceof GoalBlock) {
GoalBlock goal = (GoalBlock) iGoal;
x = goal.x;
y = goal.y;
z = goal.z;
} else {
throw new IllegalArgumentException("The goal must be a GoalXZ or GoalBlock");
}
if (y <= 0 || y >= 128) {
throw new IllegalArgumentException("The y of the goal is not between 0 and 128");
}
this.pathTo(new BlockPos(x, y, z));
}
@Override
public boolean isLoaded() {
return true;
@ -253,7 +284,6 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
public enum State {
LOCATE_JUMP("Finding spot to jump off"),
VALIDATE_PATH("Validating path"),
PAUSE("Waiting for elytra path"),
GET_TO_JUMP("Walking to takeoff"),
START_FLYING("Begin flying"),

View File

@ -18,6 +18,7 @@
package baritone.process.elytra;
import baritone.Baritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.process.IElytraProcess;
import baritone.api.process.PathingCommand;
import baritone.utils.BaritoneProcessHelper;
@ -49,6 +50,11 @@ public final class NullElytraProcess extends BaritoneProcessHelper implements IE
throw new UnsupportedOperationException("Called pathTo() on NullElytraBehavior");
}
@Override
public void pathTo(Goal destination) {
throw new UnsupportedOperationException("Called pathTo() on NullElytraBehavior");
}
@Override
public void resetState() {

View File

@ -27,6 +27,8 @@ import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor;
import baritone.process.CustomGoalProcess;
import baritone.process.ElytraProcess;
import net.minecraft.util.math.BlockPos;
import java.util.*;
@ -109,10 +111,6 @@ public class PathingControlManager implements IPathingControlManager {
p.cancelSegmentIfSafe();
break;
case FORCE_REVALIDATE_GOAL_AND_PATH:
if (!p.isPathing() && !p.getInProgress().isPresent()) {
p.secretInternalSetGoalAndPath(command);
}
break;
case REVALIDATE_GOAL_AND_PATH:
if (!p.isPathing() && !p.getInProgress().isPresent()) {
p.secretInternalSetGoalAndPath(command);
@ -209,7 +207,13 @@ public class PathingControlManager implements IPathingControlManager {
} else if (exec.commandType != PathingCommandType.DEFER) {
inControlThisTick = proc;
if (!proc.isTemporary()) {
iterator.forEachRemaining(IBaritoneProcess::onLostControl);
iterator.forEachRemaining(it -> {
// TODO: find a better way to make these behave well together
if (proc instanceof CustomGoalProcess && it instanceof ElytraProcess) {
return;
}
it.onLostControl();
});
}
return exec;
}