processes tied in priority
This commit is contained in:
parent
d144d30890
commit
580af2ab06
@ -35,6 +35,16 @@ import baritone.api.event.events.PathEvent;
|
||||
*/
|
||||
public interface IBaritoneProcess {
|
||||
|
||||
/**
|
||||
* Default priority. Most normal processes should have this value.
|
||||
* <p>
|
||||
* Some examples of processes that should have different values might include some kind of automated mob avoidance
|
||||
* that would be temporary and would forcefully take control. Same for something that pauses pathing for auto eat, etc.
|
||||
* <p>
|
||||
* The value is -1 beacuse that's what Impact 4.5's beta auto walk returns and I want to tie with it.
|
||||
*/
|
||||
double DEFAULT_PRIORITY = -1;
|
||||
|
||||
/**
|
||||
* Would this process like to be in control?
|
||||
*
|
||||
@ -82,7 +92,9 @@ public interface IBaritoneProcess {
|
||||
*
|
||||
* @return A double representing the priority
|
||||
*/
|
||||
double priority();
|
||||
default double priority() {
|
||||
return DEFAULT_PRIORITY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user-friendly name for this process. Suitable for a HUD.
|
||||
|
@ -53,4 +53,9 @@ public class PathingCommand {
|
||||
this.goal = goal;
|
||||
this.commandType = commandType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return commandType + " " + goal;
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +155,10 @@ public class MovementAscend extends Movement {
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
}
|
||||
|
||||
if (ctx.playerFeet().y < src.y) {
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
|
||||
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
|
||||
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
|
||||
ticksWithoutPlacement++;
|
||||
|
@ -148,6 +148,10 @@ public class MovementPillar extends Movement {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (ctx.playerFeet().y < src.y) {
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
|
||||
IBlockState fromDown = BlockStateInterface.get(ctx, src);
|
||||
if (MovementHelper.isWater(fromDown.getBlock()) && MovementHelper.isWater(ctx, dest)) {
|
||||
// stay centered while swimming up a water column
|
||||
|
@ -24,8 +24,6 @@ import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* As set by ExampleBaritoneControl or something idk
|
||||
*
|
||||
@ -46,7 +44,7 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
|
||||
private State state;
|
||||
|
||||
public CustomGoalProcess(Baritone baritone) {
|
||||
super(baritone, 3);
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,20 +77,20 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
switch (this.state) {
|
||||
case GOAL_SET:
|
||||
if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal() + "", this.goal + "")) {
|
||||
this.state = State.NONE;
|
||||
}
|
||||
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
case PATH_REQUESTED:
|
||||
// return FORCE_REVALIDATE_GOAL_AND_PATH just once
|
||||
PathingCommand ret = new PathingCommand(this.goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
|
||||
this.state = State.EXECUTING;
|
||||
return ret;
|
||||
case EXECUTING:
|
||||
if (calcFailed) {
|
||||
onLostControl();
|
||||
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
if (this.goal == null || this.goal.isInGoal(ctx.playerFeet())) {
|
||||
onLostControl(); // we're there xd
|
||||
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
return new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||
default:
|
||||
|
@ -31,7 +31,7 @@ public class ExploreProcess extends BaritoneProcessHelper {
|
||||
private BlockPos explorationOrigin;
|
||||
|
||||
public ExploreProcess(Baritone baritone) {
|
||||
super(baritone, 0);
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +46,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
|
||||
private List<Entity> cache;
|
||||
|
||||
public FollowProcess(Baritone baritone) {
|
||||
super(baritone, 1);
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +44,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
||||
private int tickCount = 0;
|
||||
|
||||
public GetToBlockProcess(Baritone baritone) {
|
||||
super(baritone, 2);
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -161,7 +161,10 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
||||
|
||||
@Override
|
||||
public String displayName() {
|
||||
return "Get To Block " + gettingTo;
|
||||
if (knownLocations.isEmpty()) {
|
||||
return "Exploring randomly to find " + gettingTo + ", no known locations";
|
||||
}
|
||||
return "Get To Block " + gettingTo + ", " + knownLocations.size() + " known locations";
|
||||
}
|
||||
|
||||
private synchronized void rescan(List<BlockPos> known, CalculationContext context) {
|
||||
|
@ -60,7 +60,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
private int tickCount;
|
||||
|
||||
public MineProcess(Baritone baritone) {
|
||||
super(baritone, 0);
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,12 +25,10 @@ public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper
|
||||
|
||||
protected final Baritone baritone;
|
||||
protected final IPlayerContext ctx;
|
||||
private final double priority;
|
||||
|
||||
public BaritoneProcessHelper(Baritone baritone, double priority) {
|
||||
public BaritoneProcessHelper(Baritone baritone) {
|
||||
this.baritone = baritone;
|
||||
this.ctx = baritone.getPlayerContext();
|
||||
this.priority = priority;
|
||||
baritone.getPathingControlManager().registerProcess(this);
|
||||
}
|
||||
|
||||
@ -38,9 +36,4 @@ public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper
|
||||
public boolean isTemporary() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double priority() {
|
||||
return priority;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import baritone.api.cache.IWaypoint;
|
||||
import baritone.api.event.events.ChatEvent;
|
||||
import baritone.api.pathing.goals.*;
|
||||
import baritone.api.pathing.movement.ActionCosts;
|
||||
import baritone.api.process.IBaritoneProcess;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import baritone.behavior.Behavior;
|
||||
@ -225,6 +226,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("proc")) {
|
||||
Optional<IBaritoneProcess> proc = baritone.getPathingControlManager().mostRecentInControl();
|
||||
if (!proc.isPresent()) {
|
||||
logDirect("No process is in control");
|
||||
return true;
|
||||
}
|
||||
IBaritoneProcess p = proc.get();
|
||||
logDirect("Class: " + p.getClass());
|
||||
logDirect("Priority: " + p.priority());
|
||||
logDirect("Temporary: " + p.isTemporary());
|
||||
logDirect("Display name: " + p.displayName());
|
||||
logDirect("Command: " + baritone.getPathingControlManager().mostRecentCommand());
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("version")) {
|
||||
String version = ExampleBaritoneControl.class.getPackage().getImplementationVersion();
|
||||
if (version == null) {
|
||||
|
@ -29,11 +29,11 @@ import baritone.pathing.path.PathExecutor;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PathingControlManager implements IPathingControlManager {
|
||||
private final Baritone baritone;
|
||||
private final HashSet<IBaritoneProcess> processes; // unGh
|
||||
private final List<IBaritoneProcess> active;
|
||||
private IBaritoneProcess inControlLastTick;
|
||||
private IBaritoneProcess inControlThisTick;
|
||||
private PathingCommand command;
|
||||
@ -41,14 +41,14 @@ public class PathingControlManager implements IPathingControlManager {
|
||||
public PathingControlManager(Baritone baritone) {
|
||||
this.baritone = baritone;
|
||||
this.processes = new HashSet<>();
|
||||
this.active = new ArrayList<>();
|
||||
baritone.getGameEventHandler().registerEventListener(new AbstractGameEventListener() { // needs to be after all behavior ticks
|
||||
@Override
|
||||
public void onTick(TickEvent event) {
|
||||
if (event.getType() == TickEvent.Type.OUT) {
|
||||
return;
|
||||
}
|
||||
if (event.getType() == TickEvent.Type.IN) {
|
||||
postTick();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -62,6 +62,7 @@ public class PathingControlManager implements IPathingControlManager {
|
||||
inControlLastTick = null;
|
||||
inControlThisTick = null;
|
||||
command = null;
|
||||
active.clear();
|
||||
for (IBaritoneProcess proc : processes) {
|
||||
proc.onLostControl();
|
||||
if (proc.isActive() && !proc.isTemporary()) { // it's okay only for a temporary thing (like combat pause) to maintain control even if you say to cancel
|
||||
@ -87,6 +88,7 @@ public class PathingControlManager implements IPathingControlManager {
|
||||
command = executeProcesses();
|
||||
if (command == null) {
|
||||
p.cancelSegmentIfSafe();
|
||||
p.secretInternalSetGoal(null);
|
||||
return;
|
||||
}
|
||||
switch (command.commandType) {
|
||||
@ -172,12 +174,20 @@ public class PathingControlManager implements IPathingControlManager {
|
||||
|
||||
|
||||
public PathingCommand executeProcesses() {
|
||||
Stream<IBaritoneProcess> inContention = processes.stream()
|
||||
.filter(IBaritoneProcess::isActive)
|
||||
.sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed());
|
||||
for (IBaritoneProcess process : processes) {
|
||||
if (process.isActive()) {
|
||||
if (!active.contains(process)) {
|
||||
// put a newly active process at the very front of the queue
|
||||
active.add(0, process);
|
||||
}
|
||||
} else {
|
||||
active.remove(process);
|
||||
}
|
||||
}
|
||||
// ties are broken by which was added to the beginning of the list first
|
||||
active.sort(Comparator.comparingDouble(IBaritoneProcess::priority).reversed());
|
||||
|
||||
|
||||
Iterator<IBaritoneProcess> iterator = inContention.iterator();
|
||||
Iterator<IBaritoneProcess> iterator = active.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
IBaritoneProcess proc = iterator.next();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user