Class ForcedChunkManager
java.lang.Object
net.neoforged.neoforge.common.world.chunk.ForcedChunkManager
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classForcedChunkManager.TicketOwner<T extends Comparable<? super T>>Helper class to keep track of a ticket owner by controller ID and owner objectstatic classForcedChunkManager.TicketTracker<T extends Comparable<? super T>>Helper class to manage tracking and handling loaded tickets. - 
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final TicketType<ForcedChunkManager.TicketOwner<BlockPos>>(package private) static final TicketType<ForcedChunkManager.TicketOwner<BlockPos>>private static Map<ResourceLocation,TicketController> (package private) static final TicketType<ForcedChunkManager.TicketOwner<UUID>>(package private) static final TicketType<ForcedChunkManager.TicketOwner<UUID>>private static booleanprivate static final org.apache.logging.log4j.Logger - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescription(package private) static <T extends Comparable<? super T>>
booleanforceChunk(ServerLevel level, ResourceLocation id, T owner, int chunkX, int chunkZ, boolean add, boolean ticking, TicketType<ForcedChunkManager.TicketOwner<T>> type, Function<ForcedChunksSavedData, ForcedChunkManager.TicketTracker<T>> ticketGetter) Forces a chunk to be loaded for the given mod with the given "owner".private static <T extends Comparable<? super T>>
voidforceChunk(ServerLevel level, ChunkPos pos, TicketType<ForcedChunkManager.TicketOwner<T>> type, ForcedChunkManager.TicketOwner<T> owner, boolean add, boolean ticking) Adds/Removes a ticket from the level's chunk provider with the proper levels to match the forced chunks.private static <T extends Comparable<? super T>>
voidgatherTicketsById(Map<ForcedChunkManager.TicketOwner<T>, it.unimi.dsi.fastutil.longs.LongSet> tickets, Function<TicketSet, it.unimi.dsi.fastutil.longs.LongSet> typeGetter, Map<ResourceLocation, Map<T, TicketSet>> modSortedOwnedChunks) Gathers tickets into an ID filtered map for use in providing all tickets a controller has registered to itsLoadingValidationCallback.private static <T extends Comparable<? super T>>
Map<ResourceLocation,Map<T, TicketSet>> gatherTicketsById(ForcedChunkManager.TicketTracker<T> tickets) Gathers tickets into an ID filtered map for use in providing all tickets a controller has registered to itsLoadingValidationCallback.static booleanhasForcedChunks(ServerLevel level) Checks if a level has any forced chunks.static voidinit()private static voidreadBlockForcedChunks(ResourceLocation controllerId, long chunkPos, CompoundTag modEntry, String key, Map<ForcedChunkManager.TicketOwner<BlockPos>, it.unimi.dsi.fastutil.longs.LongSet> blockForcedChunks) Reads the forge block forced chunks.private static voidreadEntityForcedChunks(ResourceLocation controllerId, long chunkPos, CompoundTag modEntry, String key, Map<ForcedChunkManager.TicketOwner<UUID>, it.unimi.dsi.fastutil.longs.LongSet> entityForcedChunks) Reads the forge entity forced chunks.static voidreadModForcedChunks(CompoundTag nbt, ForcedChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForcedChunkManager.TicketTracker<UUID> entityForcedChunks) Reads the mod forced chunks from the NBT compound.private static <T extends Comparable<? super T>>
voidreinstatePersistentChunks(ServerLevel level, TicketType<ForcedChunkManager.TicketOwner<T>> type, Map<ForcedChunkManager.TicketOwner<T>, it.unimi.dsi.fastutil.longs.LongSet> tickets, boolean ticking) Adds back any persistent forced chunks to the level's chunk provider.static voidreinstatePersistentChunks(ServerLevel level, ForcedChunksSavedData saveData) Reinstates NeoForge's forced chunks when vanilla initially loads a level and reinstates their forced chunks.private static <T extends Comparable<? super T>>
voidwriteForcedChunkOwners(Map<ResourceLocation, it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundTag>> forcedEntries, Map<ForcedChunkManager.TicketOwner<T>, it.unimi.dsi.fastutil.longs.LongSet> forcedChunks, String listKey, int listType, BiConsumer<T, ListTag> ownerWriter) private static <T extends Comparable<? super T>>
voidwriteForcedChunkOwners(Map<ResourceLocation, it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundTag>> forcedEntries, ForcedChunkManager.TicketTracker<T> tracker, String listKey, int listType, BiConsumer<T, ListTag> ownerWriter) static voidwriteModForcedChunks(CompoundTag nbt, ForcedChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForcedChunkManager.TicketTracker<UUID> entityForcedChunks) Writes the mod forced chunks into the NBT compound. 
- 
Field Details
- 
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER - 
BLOCK
 - 
BLOCK_TICKING
 - 
ENTITY
 - 
ENTITY_TICKING
 - 
initialised
private static boolean initialised - 
controllers
 
 - 
 - 
Constructor Details
- 
ForcedChunkManager
public ForcedChunkManager() 
 - 
 - 
Method Details
- 
init
@Internal public static void init() - 
hasForcedChunks
Checks if a level has any forced chunks. Mainly used for seeing if a level should continue ticking with no players in it. - 
forceChunk
static <T extends Comparable<? super T>> boolean forceChunk(ServerLevel level, ResourceLocation id, T owner, int chunkX, int chunkZ, boolean add, boolean ticking, TicketType<ForcedChunkManager.TicketOwner<T>> type, Function<ForcedChunksSavedData, ForcedChunkManager.TicketTracker<T>> ticketGetter) Forces a chunk to be loaded for the given mod with the given "owner".- Parameters:
 add-trueto force the chunk,falseto unforce the chunk.- Implementation Note:
 - Based on 
ServerLevel.setChunkForced(int, int, boolean) 
 - 
forceChunk
private static <T extends Comparable<? super T>> void forceChunk(ServerLevel level, ChunkPos pos, TicketType<ForcedChunkManager.TicketOwner<T>> type, ForcedChunkManager.TicketOwner<T> owner, boolean add, boolean ticking) Adds/Removes a ticket from the level's chunk provider with the proper levels to match the forced chunks.- Parameters:
 add-trueto force the chunk,falseto unforce the chunk.ticking-trueto make the chunk receive full chunk ticks even if there is no player nearby.- Implementation Note:
 - We use distance 2 for what we pass, as when using register/releaseTicket the ticket's level is set to 33 - distance and the level that forced chunks use is 31.
 
 - 
reinstatePersistentChunks
@Internal public static void reinstatePersistentChunks(ServerLevel level, ForcedChunksSavedData saveData) Reinstates NeoForge's forced chunks when vanilla initially loads a level and reinstates their forced chunks. This method also will validate all the forced chunks with the registeredLoadingValidationCallbacks. - 
gatherTicketsById
private static <T extends Comparable<? super T>> Map<ResourceLocation,Map<T, gatherTicketsByIdTicketSet>> (ForcedChunkManager.TicketTracker<T> tickets) Gathers tickets into an ID filtered map for use in providing all tickets a controller has registered to itsLoadingValidationCallback. - 
gatherTicketsById
private static <T extends Comparable<? super T>> void gatherTicketsById(Map<ForcedChunkManager.TicketOwner<T>, it.unimi.dsi.fastutil.longs.LongSet> tickets, Function<TicketSet, it.unimi.dsi.fastutil.longs.LongSet> typeGetter, Map<ResourceLocation, Map<T, TicketSet>> modSortedOwnedChunks) Gathers tickets into an ID filtered map for use in providing all tickets a controller has registered to itsLoadingValidationCallback. - 
reinstatePersistentChunks
private static <T extends Comparable<? super T>> void reinstatePersistentChunks(ServerLevel level, TicketType<ForcedChunkManager.TicketOwner<T>> type, Map<ForcedChunkManager.TicketOwner<T>, it.unimi.dsi.fastutil.longs.LongSet> tickets, boolean ticking) Adds back any persistent forced chunks to the level's chunk provider. - 
writeModForcedChunks
@Internal public static void writeModForcedChunks(CompoundTag nbt, ForcedChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForcedChunkManager.TicketTracker<UUID> entityForcedChunks) Writes the mod forced chunks into the NBT compound. Format is List{controllerId, List{ChunkPos, List{BlockPos}, List{UUID}}} - 
writeForcedChunkOwners
private static <T extends Comparable<? super T>> void writeForcedChunkOwners(Map<ResourceLocation, it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundTag>> forcedEntries, ForcedChunkManager.TicketTracker<T> tracker, String listKey, int listType, BiConsumer<T, ListTag> ownerWriter)  - 
writeForcedChunkOwners
private static <T extends Comparable<? super T>> void writeForcedChunkOwners(Map<ResourceLocation, it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundTag>> forcedEntries, Map<ForcedChunkManager.TicketOwner<T>, it.unimi.dsi.fastutil.longs.LongSet> forcedChunks, String listKey, int listType, BiConsumer<T, ListTag> ownerWriter)  - 
readModForcedChunks
@Internal public static void readModForcedChunks(CompoundTag nbt, ForcedChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForcedChunkManager.TicketTracker<UUID> entityForcedChunks) Reads the mod forced chunks from the NBT compound. Format is List{controllerId, List{ChunkPos, List{BlockPos}, List{UUID}}} - 
readBlockForcedChunks
private static void readBlockForcedChunks(ResourceLocation controllerId, long chunkPos, CompoundTag modEntry, String key, Map<ForcedChunkManager.TicketOwner<BlockPos>, it.unimi.dsi.fastutil.longs.LongSet> blockForcedChunks) Reads the forge block forced chunks. - 
readEntityForcedChunks
private static void readEntityForcedChunks(ResourceLocation controllerId, long chunkPos, CompoundTag modEntry, String key, Map<ForcedChunkManager.TicketOwner<UUID>, it.unimi.dsi.fastutil.longs.LongSet> entityForcedChunks) Reads the forge entity forced chunks. 
 -