Reset context on world load/unload

This commit is contained in:
Brady 2023-07-07 11:19:18 -07:00
parent 537100a5e5
commit bfb4ffcafc
No known key found for this signature in database
GPG Key ID: 73A788379A197567
1 changed files with 22 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import baritone.api.behavior.IElytraBehavior;
import baritone.api.behavior.look.IAimProcessor;
import baritone.api.behavior.look.ITickableAimProcessor;
import baritone.api.event.events.*;
import baritone.api.event.events.type.EventState;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalYLevel;
import baritone.api.pathing.movement.IMovement;
@ -75,6 +76,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
// :sunglasses:
private NetherPathfinderContext context;
private boolean forceResetContext;
private final PathManager pathManager;
private final ElytraProcess process;
@ -363,6 +365,24 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
}
}
@Override
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.forceResetContext = true;
}
} 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;
}
}
}
}
@Override
public void onChunkEvent(ChunkEvent event) {
if (event.isPostPopulate()) {
@ -435,11 +455,12 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
// Setup/reset context
final long netherSeed = Baritone.settings().elytraNetherSeed.value;
if (this.context == null || this.context.getSeed() != netherSeed) {
if (this.context == null || this.context.getSeed() != netherSeed || this.forceResetContext) {
if (this.context != null) {
this.context.destroy();
}
this.context = new NetherPathfinderContext(netherSeed);
this.forceResetContext = false;
if (this.isActive()) {
// TODO: Re-pack chunks?