Skip to content

Commit

Permalink
Merge pull request #662 from zyxkad/patch-chunky
Browse files Browse the repository at this point in the history
use tick rather than epoch time
  • Loading branch information
SirEndii authored Oct 21, 2024
2 parents eee605f + 56b4497 commit 0106dfe
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ChunkManager extends SavedData {

private static final String DATA_NAME = AdvancedPeripherals.MOD_ID + "_ForcedChunks";
private static final String FORCED_CHUNKS_TAG = "forcedChunks";
private static int tickCounter = 0;
private static long tickCounter = 0;
private final Map<UUID, LoadChunkRecord> forcedChunks = new HashMap<>();
private boolean initialized = false;

Expand Down Expand Up @@ -60,8 +60,7 @@ public static void serverTick(TickEvent.ServerTickEvent event) {
tickCounter++;
// run cleanup per chunkLoadValidTime / 10
final int checkIntervalInTick = APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() * 20 / 10;
if (tickCounter >= checkIntervalInTick) {
tickCounter = 0;
if (tickCounter % checkIntervalInTick == 0) {
ChunkManager.get(ServerLifecycleHooks.getCurrentServer().overworld()).cleanup();
}
}
Expand Down Expand Up @@ -259,7 +258,7 @@ private static class LoadChunkRecord {
this.dimensionName = dimensionName;
this.pos = pos;
this.radius = radius;
this.lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
this.lastTouch = tickCounter;
}

public static LoadChunkRecord deserialize(@NotNull CompoundTag tag) {
Expand All @@ -285,12 +284,11 @@ public void setRadius(int radius) {
}

public void touch() {
lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
lastTouch = tickCounter;
}

public boolean isValid() {
long currentEpoch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
return lastTouch + APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() >= currentEpoch;
return lastTouch + APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() * 20 >= tickCounter;
}

public @NotNull CompoundTag serialize() {
Expand Down

0 comments on commit 0106dfe

Please sign in to comment.