mirror of https://github.com/cabaletta/baritone
simplify management of elytra state
This commit is contained in:
parent
2f0497756b
commit
ff1b3e7c5f
|
@ -175,8 +175,8 @@ dependencies {
|
||||||
transitive = false
|
transitive = false
|
||||||
}
|
}
|
||||||
launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor'
|
launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor'
|
||||||
launchImplementation('dev.babbaj:nether-pathfinder:0.39')
|
launchImplementation('dev.babbaj:nether-pathfinder:0.41')
|
||||||
implementation 'dev.babbaj:nether-pathfinder:0.39'
|
implementation 'dev.babbaj:nether-pathfinder:0.41'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,24 +19,21 @@ package baritone.api.process;
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public interface IElytraProcess extends IBaritoneProcess {
|
public interface IElytraProcess extends IBaritoneProcess {
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks the nether pathfinder context to be reset when it is safe to do so. Because this operation is not
|
|
||||||
* immediate, a {@link CompletableFuture} is returned that will complete after the context has been reset.
|
|
||||||
*
|
|
||||||
* @return A {@link CompletableFuture} that is completed when the context is reset
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
CompletableFuture<Void> resetContext();
|
|
||||||
|
|
||||||
void repackChunks();
|
void repackChunks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Where it is currently flying to, null if not active
|
||||||
|
*/
|
||||||
|
BlockPos currentDestination();
|
||||||
|
|
||||||
void pathTo(BlockPos destination);
|
void pathTo(BlockPos destination);
|
||||||
|
|
||||||
void cancel();
|
/**
|
||||||
|
* Resets the state of the process but will maintain the same destination and will try to keep flying
|
||||||
|
*/
|
||||||
|
void resetState();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {@code true} if the native library loaded and elytra is actually usable
|
* @return {@code true} if the native library loaded and elytra is actually usable
|
||||||
|
|
|
@ -85,10 +85,11 @@ public class ElytraCommand extends Command {
|
||||||
final String action = args.getString();
|
final String action = args.getString();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "reset": {
|
case "reset": {
|
||||||
elytra.resetContext().whenComplete((result, ex) -> {
|
BlockPos destination = elytra.currentDestination();
|
||||||
logDirect("Context reset, repacking chunks");
|
elytra.onLostControl();
|
||||||
|
elytra.pathTo(destination);
|
||||||
elytra.repackChunks();
|
elytra.repackChunks();
|
||||||
});
|
logDirect("Reset state but still flying to same goal");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "repack": {
|
case "repack": {
|
||||||
|
|
|
@ -180,7 +180,6 @@ public class ExecutionControlCommands {
|
||||||
paused[0] = false;
|
paused[0] = false;
|
||||||
}
|
}
|
||||||
baritone.getPathingBehavior().cancelEverything();
|
baritone.getPathingBehavior().cancelEverything();
|
||||||
baritone.getElytraProcess().cancel(); // TODO: this shouldnt be necessary
|
|
||||||
logDirect("ok canceled");
|
logDirect("ok canceled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class ForceCancelCommand extends Command {
|
||||||
IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
||||||
pathingBehavior.cancelEverything();
|
pathingBehavior.cancelEverything();
|
||||||
pathingBehavior.forceCancel();
|
pathingBehavior.forceCancel();
|
||||||
baritone.getElytraProcess().cancel();
|
baritone.getElytraProcess().onLostControl(); // is this necessary?
|
||||||
logDirect("ok force canceled");
|
logDirect("ok force canceled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ package baritone.process;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.event.events.*;
|
import baritone.api.event.events.*;
|
||||||
|
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.GoalYLevel;
|
import baritone.api.pathing.goals.GoalYLevel;
|
||||||
|
@ -42,9 +43,6 @@ import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -63,14 +61,32 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
: new NullElytraProcess(baritone));
|
: new NullElytraProcess(baritone));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return behavior != null;
|
return behavior != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetState() {
|
||||||
|
BlockPos destination = this.currentDestination();
|
||||||
|
this.onLostControl();
|
||||||
|
this.pathTo(destination);
|
||||||
|
this.repackChunks();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||||
|
final long seedSetting = Baritone.settings().elytraNetherSeed.value;
|
||||||
|
if (this.behavior != null && seedSetting != behavior.context.getSeed()) {
|
||||||
|
logDirect("Nether seed changed, recalculating path");
|
||||||
|
this.resetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.behavior != null) {
|
||||||
this.behavior.onTick();
|
this.behavior.onTick();
|
||||||
|
}
|
||||||
if (calcFailed) {
|
if (calcFailed) {
|
||||||
onLostControl();
|
onLostControl();
|
||||||
logDirect("Failed to get to jump off spot, canceling");
|
logDirect("Failed to get to jump off spot, canceling");
|
||||||
|
@ -184,38 +200,13 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
public void onLostControl() {
|
public void onLostControl() {
|
||||||
this.goal = null;
|
this.goal = null;
|
||||||
this.state = State.START_FLYING; // TODO: null state?
|
this.state = State.START_FLYING; // TODO: null state?
|
||||||
if (this.behavior != null) this.behavior.cancel();
|
if (this.behavior != null) this.behavior.destroy();
|
||||||
this.behavior = null;
|
this.behavior = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String displayName0() {
|
public String displayName0() {
|
||||||
final Supplier<String> status = () -> {
|
return "Elytra - " + this.state.description;
|
||||||
switch (this.state) {
|
|
||||||
case LOCATE_JUMP:
|
|
||||||
return "Finding spot to jump off";
|
|
||||||
case PAUSE:
|
|
||||||
return "Waiting for elytra path";
|
|
||||||
case GET_TO_JUMP:
|
|
||||||
return "Walking to takeoff";
|
|
||||||
case START_FLYING:
|
|
||||||
return "Begin flying";
|
|
||||||
case FLYING:
|
|
||||||
return "Flying";
|
|
||||||
case LANDING:
|
|
||||||
return "Landing";
|
|
||||||
default:
|
|
||||||
return "Unknown";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return "Elytra - " + status.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Void> resetContext() {
|
|
||||||
return behavior.resetContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -223,6 +214,11 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
this.behavior.repackChunks();
|
this.behavior.repackChunks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockPos currentDestination() {
|
||||||
|
return this.behavior != null ? this.behavior.destination : null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pathTo(BlockPos destination) {
|
public void pathTo(BlockPos destination) {
|
||||||
this.behavior = new LegacyElytraBehavior(this.baritone, this);
|
this.behavior = new LegacyElytraBehavior(this.baritone, this);
|
||||||
|
@ -232,12 +228,6 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
this.behavior.pathTo(destination);
|
this.behavior.pathTo(destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cancel() {
|
|
||||||
if (this.behavior != null) this.behavior.cancel();
|
|
||||||
this.behavior = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLoaded() {
|
public boolean isLoaded() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -249,13 +239,19 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
LOCATE_JUMP,
|
LOCATE_JUMP("Finding spot to jump off"),
|
||||||
VALIDATE_PATH,
|
VALIDATE_PATH("Validating path"),
|
||||||
PAUSE,
|
PAUSE("Waiting for elytra path"),
|
||||||
GET_TO_JUMP,
|
GET_TO_JUMP("Walking to takeoff"),
|
||||||
START_FLYING,
|
START_FLYING("Begin flying"),
|
||||||
FLYING,
|
FLYING("Flying"),
|
||||||
LANDING
|
LANDING("Landing");
|
||||||
|
|
||||||
|
public String description;
|
||||||
|
|
||||||
|
State(String desc) {
|
||||||
|
this.description = desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -265,7 +261,13 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWorldEvent(WorldEvent event) {
|
public void onWorldEvent(WorldEvent event) {
|
||||||
if (this.behavior != null) this.behavior.onWorldEvent(event);
|
if (event.getWorld() != null && event.getState() == EventState.POST) {
|
||||||
|
// Exiting the world, just destroy
|
||||||
|
if (this.behavior != null) {
|
||||||
|
this.behavior.destroy();
|
||||||
|
this.behavior = new LegacyElytraBehavior(baritone, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,7 +23,6 @@ import baritone.api.Settings;
|
||||||
import baritone.api.behavior.look.IAimProcessor;
|
import baritone.api.behavior.look.IAimProcessor;
|
||||||
import baritone.api.behavior.look.ITickableAimProcessor;
|
import baritone.api.behavior.look.ITickableAimProcessor;
|
||||||
import baritone.api.event.events.*;
|
import baritone.api.event.events.*;
|
||||||
import baritone.api.event.events.type.EventState;
|
|
||||||
import baritone.api.pathing.goals.GoalBlock;
|
import baritone.api.pathing.goals.GoalBlock;
|
||||||
import baritone.api.utils.*;
|
import baritone.api.utils.*;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
|
@ -50,7 +49,6 @@ import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -76,8 +74,7 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
public List<BetterBlockPos> visiblePath;
|
public List<BetterBlockPos> visiblePath;
|
||||||
|
|
||||||
// :sunglasses:
|
// :sunglasses:
|
||||||
private NetherPathfinderContext context; // TODO: make this final
|
public final NetherPathfinderContext context; // TODO: make this final
|
||||||
private CompletableFuture<Void> forceResetContext;
|
|
||||||
public final PathManager pathManager;
|
public final PathManager pathManager;
|
||||||
private final ElytraProcess process;
|
private final ElytraProcess process;
|
||||||
|
|
||||||
|
@ -102,8 +99,8 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
private final int[] nextTickBoostCounter;
|
private final int[] nextTickBoostCounter;
|
||||||
|
|
||||||
private BlockStateInterface bsi;
|
private BlockStateInterface bsi;
|
||||||
private BlockStateOctreeInterface boi;
|
private final BlockStateOctreeInterface boi;
|
||||||
public BlockPos destination;
|
public BlockPos destination; // TODO: make this final?
|
||||||
|
|
||||||
private final ExecutorService solverExecutor;
|
private final ExecutorService solverExecutor;
|
||||||
private Future<Solution> solver;
|
private Future<Solution> solver;
|
||||||
|
@ -127,6 +124,7 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
this.nextTickBoostCounter = new int[2];
|
this.nextTickBoostCounter = new int[2];
|
||||||
|
|
||||||
this.context = new NetherPathfinderContext(Baritone.settings().elytraNetherSeed.value);
|
this.context = new NetherPathfinderContext(Baritone.settings().elytraNetherSeed.value);
|
||||||
|
this.boi = new BlockStateOctreeInterface(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class PathManager {
|
public final class PathManager {
|
||||||
|
@ -411,24 +409,6 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move this logic to ElytraProcess
|
|
||||||
public void onWorldEvent(WorldEvent event) {
|
|
||||||
if (event.getWorld() != null) {
|
|
||||||
if (event.getState() == EventState.PRE) {
|
|
||||||
// Reset the context when it's safe to do so on the next game tick
|
|
||||||
this.resetContext();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (event.getState() == EventState.POST) {
|
|
||||||
// Exiting the world, just destroy and invalidate the context
|
|
||||||
if (this.context != null) {
|
|
||||||
this.context.destroy();
|
|
||||||
this.context = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onChunkEvent(ChunkEvent event) {
|
public void onChunkEvent(ChunkEvent event) {
|
||||||
if (event.isPostPopulate() && this.context != null) {
|
if (event.isPostPopulate() && this.context != null) {
|
||||||
final Chunk chunk = ctx.world().getChunk(event.getX(), event.getZ());
|
final Chunk chunk = ctx.world().getChunk(event.getX(), event.getZ());
|
||||||
|
@ -436,12 +416,6 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadRenderDistance(World world) {
|
|
||||||
((IChunkProviderClient) world.getChunkProvider()).loadedChunks().forEach((l, chunk) -> {
|
|
||||||
this.context.queueForPacking(chunk);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBlockChange(BlockChangeEvent event) {
|
public void onBlockChange(BlockChangeEvent event) {
|
||||||
this.context.queueBlockUpdate(event);
|
this.context.queueBlockUpdate(event);
|
||||||
}
|
}
|
||||||
|
@ -461,24 +435,11 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void destroy() {
|
||||||
this.destination = null;
|
|
||||||
this.pathManager.clear();
|
|
||||||
this.remainingFireworkTicks = 0;
|
|
||||||
this.remainingSetBackTicks = 0;
|
|
||||||
if (this.solver != null) {
|
if (this.solver != null) {
|
||||||
this.solver.cancel(true);
|
this.solver.cancel(true);
|
||||||
this.solver = null;
|
|
||||||
}
|
}
|
||||||
this.pendingSolution = null;
|
this.context.destroy();
|
||||||
Arrays.fill(this.nextTickBoostCounter, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<Void> resetContext() {
|
|
||||||
if (this.forceResetContext == null) {
|
|
||||||
this.forceResetContext = new CompletableFuture<>();
|
|
||||||
}
|
|
||||||
return this.forceResetContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repackChunks() {
|
public void repackChunks() {
|
||||||
|
@ -486,11 +447,6 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
.forEach(this.context::queueForPacking);
|
.forEach(this.context::queueForPacking);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
|
||||||
return baritone.getPathingControlManager().mostRecentInControl()
|
|
||||||
.filter(process -> this.process == process).isPresent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTick() {
|
public void onTick() {
|
||||||
// Fetch the previous solution, regardless of if it's going to be used
|
// Fetch the previous solution, regardless of if it's going to be used
|
||||||
this.pendingSolution = null;
|
this.pendingSolution = null;
|
||||||
|
@ -504,23 +460,6 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup/reset context
|
|
||||||
final long netherSeed = Baritone.settings().elytraNetherSeed.value;
|
|
||||||
if (this.context == null || this.context.getSeed() != netherSeed || this.forceResetContext != null) {
|
|
||||||
if (this.context != null) {
|
|
||||||
this.context.destroy();
|
|
||||||
}
|
|
||||||
this.context = new NetherPathfinderContext(netherSeed);
|
|
||||||
if (this.forceResetContext != null) {
|
|
||||||
this.forceResetContext.complete(null);
|
|
||||||
this.forceResetContext = null;
|
|
||||||
}
|
|
||||||
if (this.context.getSeed() != netherSeed && this.isActive()) {
|
|
||||||
logDirect("Nether seed changed, recalculating path");
|
|
||||||
this.pathManager.pathToDestination();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tickInventoryTransactions();
|
tickInventoryTransactions();
|
||||||
|
|
||||||
// Certified mojang employee incident
|
// Certified mojang employee incident
|
||||||
|
@ -554,7 +493,6 @@ public final class LegacyElytraBehavior implements Helper {
|
||||||
|
|
||||||
// ctx AND context???? :DDD
|
// ctx AND context???? :DDD
|
||||||
this.bsi = new BlockStateInterface(ctx);
|
this.bsi = new BlockStateInterface(ctx);
|
||||||
this.boi = new BlockStateOctreeInterface(context);
|
|
||||||
this.pathManager.tick();
|
this.pathManager.tick();
|
||||||
|
|
||||||
final int playerNear = this.pathManager.getNear();
|
final int playerNear = this.pathManager.getNear();
|
||||||
|
|
|
@ -35,13 +35,13 @@ public final class NullElytraProcess extends BaritoneProcessHelper implements IE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> resetContext() {
|
public void repackChunks() {
|
||||||
throw new UnsupportedOperationException("Called resetContext() on NullElytraBehavior");
|
throw new UnsupportedOperationException("Called repackChunks() on NullElytraBehavior");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void repackChunks() {
|
public BlockPos currentDestination() {
|
||||||
throw new UnsupportedOperationException("Called repackChunks() on NullElytraBehavior");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,8 +50,8 @@ public final class NullElytraProcess extends BaritoneProcessHelper implements IE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancel() {
|
public void resetState() {
|
||||||
throw new UnsupportedOperationException("Called cancel() on NullElytraBehavior");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue