Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use tick rather than epoch time #662

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading