mirror of https://github.com/cabaletta/baritone
make elytra play nice with CustomGoalProcess
This commit is contained in:
parent
097e30850f
commit
664375a678
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package baritone.api.process;
|
package baritone.api.process;
|
||||||
|
|
||||||
|
import baritone.api.pathing.goals.Goal;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public interface IElytraProcess extends IBaritoneProcess {
|
public interface IElytraProcess extends IBaritoneProcess {
|
||||||
|
@ -30,6 +31,8 @@ public interface IElytraProcess extends IBaritoneProcess {
|
||||||
|
|
||||||
void pathTo(BlockPos destination);
|
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
|
* Resets the state of the process but will maintain the same destination and will try to keep flying
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -59,26 +59,11 @@ public class ElytraCommand extends Command {
|
||||||
if (iGoal == null) {
|
if (iGoal == null) {
|
||||||
throw new CommandInvalidStateException("No goal has been set");
|
throw new CommandInvalidStateException("No goal has been set");
|
||||||
}
|
}
|
||||||
final int x;
|
try {
|
||||||
final int y;
|
elytra.pathTo(iGoal);
|
||||||
final int z;
|
} catch (IllegalArgumentException ex) {
|
||||||
if (iGoal instanceof GoalXZ) {
|
throw new CommandInvalidStateException(ex.getMessage());
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,9 @@ public final class CustomGoalProcess extends BaritoneProcessHelper implements IC
|
||||||
public void setGoal(Goal goal) {
|
public void setGoal(Goal goal) {
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
this.mostRecentGoal = goal;
|
this.mostRecentGoal = goal;
|
||||||
|
if (baritone.getElytraProcess().isActive()) {
|
||||||
|
baritone.getElytraProcess().pathTo(goal);
|
||||||
|
}
|
||||||
if (this.state == State.NONE) {
|
if (this.state == State.NONE) {
|
||||||
this.state = State.GOAL_SET;
|
this.state = State.GOAL_SET;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import baritone.api.event.events.*;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.api.event.listener.AbstractGameEventListener;
|
import baritone.api.event.listener.AbstractGameEventListener;
|
||||||
import baritone.api.pathing.goals.Goal;
|
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.goals.GoalYLevel;
|
||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
import baritone.api.pathing.path.IPathExecutor;
|
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;
|
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
||||||
|
|
||||||
public class ElytraProcess extends BaritoneProcessHelper implements IBaritoneProcess, IElytraProcess, AbstractGameEventListener {
|
public class ElytraProcess extends BaritoneProcessHelper implements IBaritoneProcess, IElytraProcess, AbstractGameEventListener {
|
||||||
|
|
||||||
public State state;
|
public State state;
|
||||||
private Goal goal;
|
private Goal goal;
|
||||||
private LegacyElytraBehavior behavior;
|
private LegacyElytraBehavior behavior;
|
||||||
|
@ -93,7 +94,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
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();
|
final BetterBlockPos last = behavior.pathManager.path.getLast();
|
||||||
if (last != null && ctx.player().getDistanceSqToCenter(last) < (5 * 5)) {
|
if (last != null && ctx.player().getDistanceSqToCenter(last) < (5 * 5)) {
|
||||||
if (Baritone.settings().notificationOnPathComplete.value) {
|
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
|
@Override
|
||||||
public String displayName0() {
|
public String displayName0() {
|
||||||
return "Elytra - " + this.state.description;
|
return "Elytra - " + this.state.description;
|
||||||
|
@ -234,6 +240,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pathTo(BlockPos destination) {
|
public void pathTo(BlockPos destination) {
|
||||||
|
this.onLostControl();
|
||||||
this.behavior = new LegacyElytraBehavior(this.baritone, this, destination);
|
this.behavior = new LegacyElytraBehavior(this.baritone, this, destination);
|
||||||
if (ctx.world() != null) {
|
if (ctx.world() != null) {
|
||||||
this.behavior.repackChunks();
|
this.behavior.repackChunks();
|
||||||
|
@ -241,6 +248,30 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
this.behavior.pathTo();
|
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
|
@Override
|
||||||
public boolean isLoaded() {
|
public boolean isLoaded() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -253,7 +284,6 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
LOCATE_JUMP("Finding spot to jump off"),
|
LOCATE_JUMP("Finding spot to jump off"),
|
||||||
VALIDATE_PATH("Validating path"),
|
|
||||||
PAUSE("Waiting for elytra path"),
|
PAUSE("Waiting for elytra path"),
|
||||||
GET_TO_JUMP("Walking to takeoff"),
|
GET_TO_JUMP("Walking to takeoff"),
|
||||||
START_FLYING("Begin flying"),
|
START_FLYING("Begin flying"),
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package baritone.process.elytra;
|
package baritone.process.elytra;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.process.IElytraProcess;
|
import baritone.api.process.IElytraProcess;
|
||||||
import baritone.api.process.PathingCommand;
|
import baritone.api.process.PathingCommand;
|
||||||
import baritone.utils.BaritoneProcessHelper;
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
|
@ -49,6 +50,11 @@ public final class NullElytraProcess extends BaritoneProcessHelper implements IE
|
||||||
throw new UnsupportedOperationException("Called pathTo() on NullElytraBehavior");
|
throw new UnsupportedOperationException("Called pathTo() on NullElytraBehavior");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pathTo(Goal destination) {
|
||||||
|
throw new UnsupportedOperationException("Called pathTo() on NullElytraBehavior");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resetState() {
|
public void resetState() {
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ import baritone.api.process.PathingCommand;
|
||||||
import baritone.api.process.PathingCommandType;
|
import baritone.api.process.PathingCommandType;
|
||||||
import baritone.behavior.PathingBehavior;
|
import baritone.behavior.PathingBehavior;
|
||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
|
import baritone.process.CustomGoalProcess;
|
||||||
|
import baritone.process.ElytraProcess;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -109,10 +111,6 @@ public class PathingControlManager implements IPathingControlManager {
|
||||||
p.cancelSegmentIfSafe();
|
p.cancelSegmentIfSafe();
|
||||||
break;
|
break;
|
||||||
case FORCE_REVALIDATE_GOAL_AND_PATH:
|
case FORCE_REVALIDATE_GOAL_AND_PATH:
|
||||||
if (!p.isPathing() && !p.getInProgress().isPresent()) {
|
|
||||||
p.secretInternalSetGoalAndPath(command);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case REVALIDATE_GOAL_AND_PATH:
|
case REVALIDATE_GOAL_AND_PATH:
|
||||||
if (!p.isPathing() && !p.getInProgress().isPresent()) {
|
if (!p.isPathing() && !p.getInProgress().isPresent()) {
|
||||||
p.secretInternalSetGoalAndPath(command);
|
p.secretInternalSetGoalAndPath(command);
|
||||||
|
@ -209,7 +207,13 @@ public class PathingControlManager implements IPathingControlManager {
|
||||||
} else if (exec.commandType != PathingCommandType.DEFER) {
|
} else if (exec.commandType != PathingCommandType.DEFER) {
|
||||||
inControlThisTick = proc;
|
inControlThisTick = proc;
|
||||||
if (!proc.isTemporary()) {
|
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;
|
return exec;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue