Package net.minecraftforge.common.world
Class ForgeChunkManager
java.lang.Object
net.minecraftforge.common.world.ForgeChunkManager
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static class
Class to help mods remove no longer valid tickets.static class
ForgeChunkManager.TicketOwner<T extends Comparable<? super T>>
Helper class to keep track of a ticket owner by modid and owner objectstatic class
ForgeChunkManager.TicketTracker<T extends Comparable<? super T>>
Helper class to manage tracking and handling loaded tickets. -
Field Summary
Modifier and TypeFieldDescriptionprivate static TicketType<ForgeChunkManager.TicketOwner<BlockPos>>
private static TicketType<ForgeChunkManager.TicketOwner<BlockPos>>
private static Map<String,ForgeChunkManager.LoadingValidationCallback>
private static TicketType<ForgeChunkManager.TicketOwner<UUID>>
private static TicketType<ForgeChunkManager.TicketOwner<UUID>>
private static org.apache.logging.log4j.Logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
forceChunk(ServerLevel world, String modId, UUID owner, int chunkX, int chunkZ, boolean add, boolean ticking)
Forces a chunk to be loaded for the given mod with the "owner" of the ticket being a given UUID.static boolean
forceChunk(ServerLevel world, String modId, BlockPos owner, int chunkX, int chunkZ, boolean add, boolean ticking)
Forces a chunk to be loaded for the given mod with the "owner" of the ticket being a given block position.static boolean
forceChunk(ServerLevel world, String modId, Entity owner, int chunkX, int chunkZ, boolean add, boolean ticking)
Forces a chunk to be loaded for the given mod with the "owner" of the ticket being the UUID of the given entity.private static <T extends Comparable<? super T>>
booleanforceChunk(ServerLevel world, String modId, T owner, int chunkX, int chunkZ, boolean add, boolean ticking, TicketType<ForgeChunkManager.TicketOwner<T>> type, Function<ForcedChunksSavedData,ForgeChunkManager.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 world, ChunkPos pos, TicketType<ForgeChunkManager.TicketOwner<T>> type, ForgeChunkManager.TicketOwner<T> owner, boolean add, boolean ticking)
Adds/Removes a ticket from the world's chunk provider with the proper levels to match the forced chunks.private static <T extends Comparable<? super T>>
voidgatherTicketsByModId(Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> tickets, Function<com.mojang.datafixers.util.Pair<it.unimi.dsi.fastutil.longs.LongSet,it.unimi.dsi.fastutil.longs.LongSet>,it.unimi.dsi.fastutil.longs.LongSet> typeGetter, Map<String,Map<T,com.mojang.datafixers.util.Pair<it.unimi.dsi.fastutil.longs.LongSet,it.unimi.dsi.fastutil.longs.LongSet>>> modSortedOwnedChunks)
Gathers tickets into a mod filtered map for use in providing all tickets a mod has registered to itsForgeChunkManager.LoadingValidationCallback
.private static <T extends Comparable<? super T>>
Map<String,Map<T,com.mojang.datafixers.util.Pair<it.unimi.dsi.fastutil.longs.LongSet,it.unimi.dsi.fastutil.longs.LongSet>>>gatherTicketsByModId(ForgeChunkManager.TicketTracker<T> tickets)
Gathers tickets into a mod filtered map for use in providing all tickets a mod has registered to itsForgeChunkManager.LoadingValidationCallback
.static boolean
hasForcedChunks(ServerLevel world)
Checks if a world has any forced chunks.private static void
readBlockForcedChunks(String modId, long chunkPos, CompoundTag modEntry, String key, Map<ForgeChunkManager.TicketOwner<BlockPos>,it.unimi.dsi.fastutil.longs.LongSet> blockForcedChunks)
Reads the forge block forced chunks.private static void
readEntityForcedChunks(String modId, long chunkPos, CompoundTag modEntry, String key, Map<ForgeChunkManager.TicketOwner<UUID>,it.unimi.dsi.fastutil.longs.LongSet> entityForcedChunks)
Reads the forge entity forced chunks.static void
readForgeForcedChunks(CompoundTag nbt, ForgeChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForgeChunkManager.TicketTracker<UUID> entityForcedChunks)
Reads the forge forced chunks from the NBT compound.private static <T extends Comparable<? super T>>
voidreinstatePersistentChunks(ServerLevel world, TicketType<ForgeChunkManager.TicketOwner<T>> type, Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> tickets, boolean ticking)
Adds back any persistent forced chunks to the world's chunk provider.static void
reinstatePersistentChunks(ServerLevel world, ForcedChunksSavedData saveData)
Reinstates forge's forced chunks when vanilla initially loads a world and reinstates their forced chunks.static void
setForcedChunkLoadingCallback(String modId, ForgeChunkManager.LoadingValidationCallback callback)
Sets the forced chunk loading validation callback for the given mod.private static <T extends Comparable<? super T>>
voidwriteForcedChunkOwners(Map<String,it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundTag>> forcedEntries, Map<ForgeChunkManager.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<String,it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundTag>> forcedEntries, ForgeChunkManager.TicketTracker<T> tracker, String listKey, int listType, BiConsumer<T,ListTag> ownerWriter)
static void
writeForgeForcedChunks(CompoundTag nbt, ForgeChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForgeChunkManager.TicketTracker<UUID> entityForcedChunks)
Writes the forge forced chunks into the NBT compound.
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
BLOCK
-
BLOCK_TICKING
-
ENTITY
-
ENTITY_TICKING
-
callbacks
-
-
Constructor Details
-
ForgeChunkManager
public ForgeChunkManager()
-
-
Method Details
-
setForcedChunkLoadingCallback
public static void setForcedChunkLoadingCallback(String modId, ForgeChunkManager.LoadingValidationCallback callback)Sets the forced chunk loading validation callback for the given mod. This allows for validating and removing no longer valid tickets on world load. -
hasForcedChunks
Checks if a world has any forced chunks. Mainly used for seeing if a world should continue ticking with no players in it. -
forceChunk
public static boolean forceChunk(ServerLevel world, String modId, BlockPos owner, int chunkX, int chunkZ, boolean add, boolean ticking)Forces a chunk to be loaded for the given mod with the "owner" of the ticket being a given block position.- Parameters:
add
-true
to force the chunk,false
to unforce the chunk.ticking
-true
to make the chunk receive full chunk ticks even if there is no player nearby.
-
forceChunk
public static boolean forceChunk(ServerLevel world, String modId, Entity owner, int chunkX, int chunkZ, boolean add, boolean ticking)Forces a chunk to be loaded for the given mod with the "owner" of the ticket being the UUID of the given entity.- Parameters:
add
-true
to force the chunk,false
to unforce the chunk.ticking
-true
to make the chunk receive full chunk ticks even if there is no player nearby.
-
forceChunk
public static boolean forceChunk(ServerLevel world, String modId, UUID owner, int chunkX, int chunkZ, boolean add, boolean ticking)Forces a chunk to be loaded for the given mod with the "owner" of the ticket being a given UUID.- Parameters:
add
-true
to force the chunk,false
to unforce the chunk.ticking
-true
to make the chunk receive full chunk ticks even if there is no player nearby.
-
forceChunk
private static <T extends Comparable<? super T>> boolean forceChunk(ServerLevel world, String modId, T owner, int chunkX, int chunkZ, boolean add, boolean ticking, TicketType<ForgeChunkManager.TicketOwner<T>> type, Function<ForcedChunksSavedData,ForgeChunkManager.TicketTracker<T>> ticketGetter)Forces a chunk to be loaded for the given mod with the given "owner".- Parameters:
add
-true
to force the chunk,false
to unforce the chunk.
-
forceChunk
private static <T extends Comparable<? super T>> void forceChunk(ServerLevel world, ChunkPos pos, TicketType<ForgeChunkManager.TicketOwner<T>> type, ForgeChunkManager.TicketOwner<T> owner, boolean add, boolean ticking)Adds/Removes a ticket from the world's chunk provider with the proper levels to match the forced chunks.- Parameters:
add
-true
to force the chunk,false
to unforce the chunk.ticking
-true
to make the chunk receive full chunk ticks even if there is no player nearby.
-
reinstatePersistentChunks
Reinstates forge's forced chunks when vanilla initially loads a world and reinstates their forced chunks. This method also will validate all of forge's forced chunks using and registeredForgeChunkManager.LoadingValidationCallback
. -
gatherTicketsByModId
private static <T extends Comparable<? super T>> Map<String,Map<T,com.mojang.datafixers.util.Pair<it.unimi.dsi.fastutil.longs.LongSet,it.unimi.dsi.fastutil.longs.LongSet>>> gatherTicketsByModId(ForgeChunkManager.TicketTracker<T> tickets)Gathers tickets into a mod filtered map for use in providing all tickets a mod has registered to itsForgeChunkManager.LoadingValidationCallback
. -
gatherTicketsByModId
private static <T extends Comparable<? super T>> void gatherTicketsByModId(Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> tickets, Function<com.mojang.datafixers.util.Pair<it.unimi.dsi.fastutil.longs.LongSet,it.unimi.dsi.fastutil.longs.LongSet>,it.unimi.dsi.fastutil.longs.LongSet> typeGetter, Map<String,Map<T,com.mojang.datafixers.util.Pair<it.unimi.dsi.fastutil.longs.LongSet,it.unimi.dsi.fastutil.longs.LongSet>>> modSortedOwnedChunks)Gathers tickets into a mod filtered map for use in providing all tickets a mod has registered to itsForgeChunkManager.LoadingValidationCallback
. -
reinstatePersistentChunks
private static <T extends Comparable<? super T>> void reinstatePersistentChunks(ServerLevel world, TicketType<ForgeChunkManager.TicketOwner<T>> type, Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> tickets, boolean ticking)Adds back any persistent forced chunks to the world's chunk provider. -
writeForgeForcedChunks
public static void writeForgeForcedChunks(CompoundTag nbt, ForgeChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForgeChunkManager.TicketTracker<UUID> entityForcedChunks)Writes the forge forced chunks into the NBT compound. Format is List{modid, List{ChunkPos, List{BlockPos}, List{UUID}}} -
writeForcedChunkOwners
private static <T extends Comparable<? super T>> void writeForcedChunkOwners(Map<String,it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundTag>> forcedEntries, ForgeChunkManager.TicketTracker<T> tracker, String listKey, int listType, BiConsumer<T,ListTag> ownerWriter) -
writeForcedChunkOwners
private static <T extends Comparable<? super T>> void writeForcedChunkOwners(Map<String,it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundTag>> forcedEntries, Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> forcedChunks, String listKey, int listType, BiConsumer<T,ListTag> ownerWriter) -
readForgeForcedChunks
public static void readForgeForcedChunks(CompoundTag nbt, ForgeChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForgeChunkManager.TicketTracker<UUID> entityForcedChunks)Reads the forge forced chunks from the NBT compound. Format is List{modid, List{ChunkPos, List{BlockPos}, List{UUID}}} -
readBlockForcedChunks
private static void readBlockForcedChunks(String modId, long chunkPos, CompoundTag modEntry, String key, Map<ForgeChunkManager.TicketOwner<BlockPos>,it.unimi.dsi.fastutil.longs.LongSet> blockForcedChunks)Reads the forge block forced chunks. -
readEntityForcedChunks
private static void readEntityForcedChunks(String modId, long chunkPos, CompoundTag modEntry, String key, Map<ForgeChunkManager.TicketOwner<UUID>,it.unimi.dsi.fastutil.longs.LongSet> entityForcedChunks)Reads the forge entity forced chunks.
-