Skip to content

Chunk Loading Mechanism

Henry Lin edited this page May 30, 2024 · 8 revisions

This page covers some general principles of chunk loading that apply to all modes of chunk loading offered by this mod.

What works and what doesn't work

Feature Status Explanation
Block updates ✔️ Features based on block updates, such as most redstone components, function properly in force-loaded chunks.
Block entities ✔️ Block entities are ticked in force-loaded chunks, so Create factories function properly.
Entities ✔️ Entities are ticked in force-loaded chunks, so contraptions and animal farms (such as egg farms) function properly.
Random tick Random ticks only happen near a player, so crops won't grow in force-loaded chunks if no one is nearby.
Mob spawning Mob spawning only happens near a player (with additional restrictions), so all mob farms do not function in force-loaded chunks if no one is nearby.

Chunk Loading Foundation

A detailed explanation of Minecraft's chunk-loading system can be found on the Wiki.

All chunks force-loaded by this mod are entity-ticking, corresponding to a forced ticket with a level of 31 as explained by the article above. Internally, this is achieved via the ForgeChunkManager, which creates the load tickets and handles saving/loading from disk. This has several implications:

  • It works in all dimensions, including custom dimensions (in theory).
  • Loading chunks with this mod has the same effect as loading chunks via the /forceload command, which means chunks remain loaded even if there are no players in the dimension, and the effect persists across game restarts.
  • Force-loading the same chunk in multiple ways does not increase lag.
  • When one chunk is force-loaded, a 5x5 chunk area centered around that chunk is loaded into RAM, with chunks closer to the center having more features enabled.

Power Loader's Implementation

For reliable chunk loading, Power Loader keeps a list of currently force-loaded chunks in each chunk loader block. This ensures that no chunks are lost or left loaded forever when the game is running.

However, this list is not serialized and saved to disk by Power Loader because the ForgeChunkManager already handles this. When the server is restarted, Forge loads the list of force-loaded chunks from disk and hands the list to Power Loader for verification. Chunks loaded by static chunk loaders are verified instantly, and invalid entries are removed/unloaded. Chunks loaded by entities (such as contraptions, trains, and train stations) are verified later when the entity is properly loaded and ticking. If an entity had force-loaded chunks before the server restart, but no longer exists after the restart, those chunks will be unloaded after a short delay.

It is important to note that all chunk-loading logic is server-side only. The lit-up core of a chunk loader block is not a perfectly accurate representation of its status, especially if the client is desynced due to network issues or if the block is under the "unloading grace period". Check the server's debug logs for CPL: entries if you want to know what Power Loader is doing.