Skip to content

Commit 0106dfe

Browse files
authored
Merge pull request #662 from zyxkad/patch-chunky
use tick rather than epoch time
2 parents eee605f + 56b4497 commit 0106dfe

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/main/java/de/srendi/advancedperipherals/common/util/ChunkManager.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ChunkManager extends SavedData {
2727

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

@@ -60,8 +60,7 @@ public static void serverTick(TickEvent.ServerTickEvent event) {
6060
tickCounter++;
6161
// run cleanup per chunkLoadValidTime / 10
6262
final int checkIntervalInTick = APConfig.PERIPHERALS_CONFIG.chunkLoadValidTime.get() * 20 / 10;
63-
if (tickCounter >= checkIntervalInTick) {
64-
tickCounter = 0;
63+
if (tickCounter % checkIntervalInTick == 0) {
6564
ChunkManager.get(ServerLifecycleHooks.getCurrentServer().overworld()).cleanup();
6665
}
6766
}
@@ -259,7 +258,7 @@ private static class LoadChunkRecord {
259258
this.dimensionName = dimensionName;
260259
this.pos = pos;
261260
this.radius = radius;
262-
this.lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
261+
this.lastTouch = tickCounter;
263262
}
264263

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

287286
public void touch() {
288-
lastTouch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
287+
lastTouch = tickCounter;
289288
}
290289

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

296294
public @NotNull CompoundTag serialize() {

0 commit comments

Comments
 (0)