From 56b4497dc1f00627933cadd63f2f89e6bb25d95b Mon Sep 17 00:00:00 2001 From: zyxkad Date: Wed, 16 Oct 2024 12:19:59 -0600 Subject: [PATCH] use tick rather than epoch time --- .../common/util/ChunkManager.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java index 3b338284d..4a916782e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java @@ -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 forcedChunks = new HashMap<>(); private boolean initialized = false; @@ -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(); } } @@ -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) { @@ -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() {