cull far away chunks from the cache

This commit is contained in:
Babbaj 2023-07-16 01:19:51 -04:00
parent 6f99f891dc
commit 76d3a13f58
No known key found for this signature in database
GPG Key ID: F044309848A07CAC
4 changed files with 28 additions and 6 deletions

View File

@ -175,8 +175,8 @@ dependencies {
transitive = false
}
launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor'
launchImplementation('dev.babbaj:nether-pathfinder:0.24')
implementation 'dev.babbaj:nether-pathfinder:0.24'
launchImplementation('dev.babbaj:nether-pathfinder:0.34')
implementation 'dev.babbaj:nether-pathfinder:0.34'
testImplementation 'junit:junit:4.12'
}

View File

@ -38,6 +38,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
@ -1404,6 +1405,16 @@ public final class Settings {
*/
public final Setting<Integer> elytraMinimumDurability = new Setting<>(5);
/**
* Time between culling far away chunks from the nether pathfinder chunk cache
*/
public final Setting<Long> elytraTimeBetweenCacheCullSecs = new Setting<>(TimeUnit.MINUTES.toSeconds(3));
/**
* Maximum distance chunks can be before being culled from the nether pathfinder chunk cache
*/
public final Setting<Integer> elytraCacheCullDistance = new Setting<>(5000);
/**
* A map of lowercase setting field names to their respective setting
*/

View File

@ -118,9 +118,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
private Solution pendingSolution;
private boolean solveNextTick;
private long timeLastCacheCull = 0L;
// auto swap
private int invTickCountdown = 0;
private final Queue<Runnable> transactionQueue = new LinkedList<>();
private final Queue<Runnable> invTransactionQueue = new LinkedList<>();
private ElytraBehavior(Baritone baritone) {
super(baritone);
@ -516,6 +518,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
if (event.getType() == TickEvent.Type.OUT) {
return;
}
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.timeLastCacheCull = now;
}
// Fetch the previous solution, regardless of if it's going to be used
this.pendingSolution = null;
@ -1264,7 +1271,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
private void tickInventoryTransactions() {
if (invTickCountdown <= 0) {
Runnable r = transactionQueue.poll();
Runnable r = invTransactionQueue.poll();
if (r != null) {
r.run();
invTickCountdown = Baritone.settings().ticksBetweenInventoryMoves.value;
@ -1274,7 +1281,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
}
private void queueWindowClick(int windowId, int slotId, int button, ClickType type) {
transactionQueue.add(() -> ctx.playerController().windowClick(windowId, slotId, button, type, ctx.player()));
invTransactionQueue.add(() -> ctx.playerController().windowClick(windowId, slotId, button, type, ctx.player()));
}
private int findGoodElytra() {
@ -1289,7 +1296,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
}
private void trySwapElytra() {
if (!Baritone.settings().elytraAutoSwap.value || !transactionQueue.isEmpty()) {
if (!Baritone.settings().elytraAutoSwap.value || !invTransactionQueue.isEmpty()) {
return;
}

View File

@ -57,6 +57,10 @@ public final class NetherPathfinderContext {
this.executor = Executors.newSingleThreadExecutor();
}
public void queueCacheCulling(int chunkX, int chunkZ, int maxDistanceBlocks) {
this.executor.execute(() -> NetherPathfinder.cullFarChunks(this.context, chunkX, chunkZ, maxDistanceBlocks));
}
public void queueForPacking(final Chunk chunkIn) {
final SoftReference<Chunk> ref = new SoftReference<>(chunkIn);
this.executor.execute(() -> {