mirror of https://github.com/cabaletta/baritone
Merge pull request #4070 from babbaj/elytra
fixes for comments in elytra pr
This commit is contained in:
commit
2164857408
|
@ -58,6 +58,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
|||
public State state;
|
||||
private boolean goingToLandingSpot;
|
||||
private BetterBlockPos landingSpot;
|
||||
private boolean reachedGoal; // this basically just prevents potential notification spam
|
||||
private Goal goal;
|
||||
private ElytraBehavior behavior;
|
||||
|
||||
|
@ -81,8 +82,10 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
|||
public void resetState() {
|
||||
BlockPos destination = this.currentDestination();
|
||||
this.onLostControl();
|
||||
this.pathTo(destination);
|
||||
this.repackChunks();
|
||||
if (destination != null) {
|
||||
this.pathTo(destination);
|
||||
this.repackChunks();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,27 +107,29 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
|||
if (ctx.player().isElytraFlying() && this.state != State.LANDING) {
|
||||
final BetterBlockPos last = this.behavior.pathManager.path.getLast();
|
||||
if (last != null && ctx.player().getDistanceSqToCenter(last) < 1) {
|
||||
if (Baritone.settings().notificationOnPathComplete.value) {
|
||||
if (Baritone.settings().notificationOnPathComplete.value && !reachedGoal) {
|
||||
logNotification("Pathing complete", false);
|
||||
}
|
||||
if (Baritone.settings().disconnectOnArrival.value) {
|
||||
if (Baritone.settings().disconnectOnArrival.value && !reachedGoal) {
|
||||
// don't be active when the user logs back in
|
||||
this.onLostControl();
|
||||
ctx.world().sendQuittingDisconnectingPacket();
|
||||
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
reachedGoal = true;
|
||||
|
||||
if (!goingToLandingSpot) {
|
||||
BetterBlockPos landingSpot = findSafeLandingSpot();
|
||||
// if this fails we will just keep orbiting the last node until we run out of rockets or the user intervenes
|
||||
if (landingSpot != null) {
|
||||
this.pathTo(landingSpot);
|
||||
this.landingSpot = landingSpot;
|
||||
this.goingToLandingSpot = true;
|
||||
return this.onTick(calcFailed, isSafeToCancel);
|
||||
}
|
||||
// don't spam call findLandingSpot if it somehow fails (it's slow)
|
||||
this.goingToLandingSpot = true;
|
||||
} else {
|
||||
// we are goingToLandingSpot and we are in the in the last node of the path
|
||||
this.state = State.LANDING;
|
||||
}
|
||||
this.state = State.LANDING;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,6 +233,7 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
|
|||
public void onLostControl() {
|
||||
this.goal = null;
|
||||
this.goingToLandingSpot = false;
|
||||
this.reachedGoal = false;
|
||||
this.state = State.START_FLYING; // TODO: null state?
|
||||
if (this.behavior != null) {
|
||||
this.behavior.destroy();
|
||||
|
|
|
@ -27,7 +27,7 @@ public final class BlockStateOctreeInterface {
|
|||
|
||||
private final NetherPathfinderContext context;
|
||||
private final long contextPtr;
|
||||
volatile long chunkPtr;
|
||||
transient long chunkPtr;
|
||||
|
||||
// Guarantee that the first lookup will fetch the context by setting MAX_VALUE
|
||||
private int prevChunkX = Integer.MAX_VALUE;
|
||||
|
@ -39,19 +39,16 @@ public final class BlockStateOctreeInterface {
|
|||
}
|
||||
|
||||
public boolean get0(final int x, final int y, final int z) {
|
||||
if ((y | (128 - y)) < 0) {
|
||||
if ((y | (127 - y)) < 0) {
|
||||
return false;
|
||||
}
|
||||
final int chunkX = x >> 4;
|
||||
final int chunkZ = z >> 4;
|
||||
long pointer = this.chunkPtr;
|
||||
if (pointer == 0 | ((chunkX ^ this.prevChunkX) | (chunkZ ^ this.prevChunkZ)) != 0) {
|
||||
if (this.chunkPtr == 0 | ((chunkX ^ this.prevChunkX) | (chunkZ ^ this.prevChunkZ)) != 0) {
|
||||
this.prevChunkX = chunkX;
|
||||
this.prevChunkZ = chunkZ;
|
||||
synchronized (this.context.cacheLock) {
|
||||
this.chunkPtr = pointer = NetherPathfinder.getOrCreateChunk(this.contextPtr, chunkX, chunkZ);
|
||||
}
|
||||
this.chunkPtr = NetherPathfinder.getOrCreateChunk(this.contextPtr, chunkX, chunkZ);
|
||||
}
|
||||
return Octree.getBlock(pointer, x & 0xF, y & 0x7F, z & 0xF);
|
||||
return Octree.getBlock(this.chunkPtr, x & 0xF, y & 0x7F, z & 0xF);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -446,6 +446,17 @@ public final class ElytraBehavior implements Helper {
|
|||
}
|
||||
|
||||
public void onTick() {
|
||||
synchronized (this.context.cullingLock) {
|
||||
this.onTick0();
|
||||
}
|
||||
final long now = System.currentTimeMillis();
|
||||
if ((now - this.timeLastCacheCull) / 1000 > Baritone.settings().elytraTimeBetweenCacheCullSecs.value) {
|
||||
this.context.queueCacheCulling(ctx.player().chunkCoordX, ctx.player().chunkCoordZ, Baritone.settings().elytraCacheCullDistance.value, this.boi);
|
||||
this.timeLastCacheCull = now;
|
||||
}
|
||||
}
|
||||
|
||||
private void onTick0() {
|
||||
// Fetch the previous solution, regardless of if it's going to be used
|
||||
this.pendingSolution = null;
|
||||
if (this.solver != null) {
|
||||
|
@ -498,12 +509,6 @@ public final class ElytraBehavior implements Helper {
|
|||
Math.max(playerNear - 30, 0),
|
||||
Math.min(playerNear + 100, path.size())
|
||||
);
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
if ((now - this.timeLastCacheCull) / 1000 > Baritone.settings().elytraTimeBetweenCacheCullSecs.value) {
|
||||
this.context.queueCacheCulling(ctx.player().chunkCoordX, ctx.player().chunkCoordZ, Baritone.settings().elytraCacheCullDistance.value, this.boi);
|
||||
this.timeLastCacheCull = now;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,7 +38,6 @@ import java.util.concurrent.CompletableFuture;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
|
@ -46,7 +45,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
public final class NetherPathfinderContext {
|
||||
|
||||
private static final IBlockState AIR_BLOCK_STATE = Blocks.AIR.getDefaultState();
|
||||
public final Object cacheLock = new Object();
|
||||
// This lock must be held while there are active pointers to chunks in java,
|
||||
// but we just hold it for the entire tick so we don't have to think much about it.
|
||||
public final Object cullingLock = new Object();
|
||||
|
||||
// Visible for access in BlockStateOctreeInterface
|
||||
final long context;
|
||||
|
@ -61,7 +62,7 @@ public final class NetherPathfinderContext {
|
|||
|
||||
public void queueCacheCulling(int chunkX, int chunkZ, int maxDistanceBlocks, BlockStateOctreeInterface boi) {
|
||||
this.executor.execute(() -> {
|
||||
synchronized (this.cacheLock) {
|
||||
synchronized (this.cullingLock) {
|
||||
boi.chunkPtr = 0L;
|
||||
NetherPathfinder.cullFarChunks(this.context, chunkX, chunkZ, maxDistanceBlocks);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue