Package net.minecraftforge.common.world
Class ForgeChunkManager
- java.lang.Object
-
- net.minecraftforge.common.world.ForgeChunkManager
-
@ParametersAreNonnullByDefault public class ForgeChunkManager extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ForgeChunkManager.LoadingValidationCallback
static class
ForgeChunkManager.TicketHelper
Class to help mods remove no longer valid tickets.static class
ForgeChunkManager.TicketOwner<T extends java.lang.Comparable<? super T>>
Helper class to keep track of a ticket owner by modid and owner objectstatic class
ForgeChunkManager.TicketTracker<T extends java.lang.Comparable<? super T>>
Helper class to manage tracking and handling loaded tickets.
-
Field Summary
Fields Modifier and Type Field Description private static TicketType<ForgeChunkManager.TicketOwner<BlockPos>>
BLOCK
private static TicketType<ForgeChunkManager.TicketOwner<BlockPos>>
BLOCK_TICKING
private static java.util.Map<java.lang.String,ForgeChunkManager.LoadingValidationCallback>
callbacks
private static TicketType<ForgeChunkManager.TicketOwner<java.util.UUID>>
ENTITY
private static TicketType<ForgeChunkManager.TicketOwner<java.util.UUID>>
ENTITY_TICKING
private static org.apache.logging.log4j.Logger
LOGGER
-
Constructor Summary
Constructors Constructor Description ForgeChunkManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
forceChunk(ServerWorld world, java.lang.String modId, java.util.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(ServerWorld world, java.lang.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.static boolean
forceChunk(ServerWorld world, java.lang.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.private static <T extends java.lang.Comparable<? super T>>
booleanforceChunk(ServerWorld world, java.lang.String modId, T owner, int chunkX, int chunkZ, boolean add, boolean ticking, TicketType<ForgeChunkManager.TicketOwner<T>> type, java.util.function.Function<ForcedChunksSaveData,ForgeChunkManager.TicketTracker<T>> ticketGetter)
Forces a chunk to be loaded for the given mod with the given "owner".private static <T extends java.lang.Comparable<? super T>>
voidforceChunk(ServerWorld 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 java.lang.Comparable<? super T>>
voidgatherTicketsByModId(java.util.Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> tickets, java.util.function.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, java.util.Map<java.lang.String,java.util.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 java.lang.Comparable<? super T>>
java.util.Map<java.lang.String,java.util.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(ServerWorld world)
Checks if a world has any forced chunks.private static void
readBlockForcedChunks(java.lang.String modId, long chunkPos, CompoundNBT modEntry, java.lang.String key, java.util.Map<ForgeChunkManager.TicketOwner<BlockPos>,it.unimi.dsi.fastutil.longs.LongSet> blockForcedChunks)
Reads the forge block forced chunks.private static void
readEntityForcedChunks(java.lang.String modId, long chunkPos, CompoundNBT modEntry, java.lang.String key, java.util.Map<ForgeChunkManager.TicketOwner<java.util.UUID>,it.unimi.dsi.fastutil.longs.LongSet> entityForcedChunks)
Reads the forge entity forced chunks.static void
readForgeForcedChunks(CompoundNBT nbt, ForgeChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForgeChunkManager.TicketTracker<java.util.UUID> entityForcedChunks)
Reads the forge forced chunks from the NBT compound.static void
reinstatePersistentChunks(ServerWorld world, ForcedChunksSaveData saveData)
Reinstates forge's forced chunks when vanilla initially loads a world and reinstates their forced chunks.private static <T extends java.lang.Comparable<? super T>>
voidreinstatePersistentChunks(ServerWorld world, TicketType<ForgeChunkManager.TicketOwner<T>> type, java.util.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
setForcedChunkLoadingCallback(java.lang.String modId, ForgeChunkManager.LoadingValidationCallback callback)
Sets the forced chunk loading validation callback for the given mod.private static <T extends java.lang.Comparable<? super T>>
voidwriteForcedChunkOwners(java.util.Map<java.lang.String,it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundNBT>> forcedEntries, java.util.Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> forcedChunks, java.lang.String listKey, int listType, java.util.function.BiConsumer<T,ListNBT> ownerWriter)
private static <T extends java.lang.Comparable<? super T>>
voidwriteForcedChunkOwners(java.util.Map<java.lang.String,it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundNBT>> forcedEntries, ForgeChunkManager.TicketTracker<T> tracker, java.lang.String listKey, int listType, java.util.function.BiConsumer<T,ListNBT> ownerWriter)
static void
writeForgeForcedChunks(CompoundNBT nbt, ForgeChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForgeChunkManager.TicketTracker<java.util.UUID> entityForcedChunks)
Writes the forge forced chunks into the NBT compound.
-
-
-
Field Detail
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER
-
BLOCK
private static final TicketType<ForgeChunkManager.TicketOwner<BlockPos>> BLOCK
-
BLOCK_TICKING
private static final TicketType<ForgeChunkManager.TicketOwner<BlockPos>> BLOCK_TICKING
-
ENTITY
private static final TicketType<ForgeChunkManager.TicketOwner<java.util.UUID>> ENTITY
-
ENTITY_TICKING
private static final TicketType<ForgeChunkManager.TicketOwner<java.util.UUID>> ENTITY_TICKING
-
callbacks
private static final java.util.Map<java.lang.String,ForgeChunkManager.LoadingValidationCallback> callbacks
-
-
Method Detail
-
setForcedChunkLoadingCallback
public static void setForcedChunkLoadingCallback(java.lang.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
public static boolean hasForcedChunks(ServerWorld world)
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(ServerWorld world, java.lang.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(ServerWorld world, java.lang.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(ServerWorld world, java.lang.String modId, java.util.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 java.lang.Comparable<? super T>> boolean forceChunk(ServerWorld world, java.lang.String modId, T owner, int chunkX, int chunkZ, boolean add, boolean ticking, TicketType<ForgeChunkManager.TicketOwner<T>> type, java.util.function.Function<ForcedChunksSaveData,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 java.lang.Comparable<? super T>> void forceChunk(ServerWorld 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
public static void reinstatePersistentChunks(ServerWorld world, ForcedChunksSaveData saveData)
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 java.lang.Comparable<? super T>> java.util.Map<java.lang.String,java.util.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 java.lang.Comparable<? super T>> void gatherTicketsByModId(java.util.Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> tickets, java.util.function.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, java.util.Map<java.lang.String,java.util.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 java.lang.Comparable<? super T>> void reinstatePersistentChunks(ServerWorld world, TicketType<ForgeChunkManager.TicketOwner<T>> type, java.util.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(CompoundNBT nbt, ForgeChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForgeChunkManager.TicketTracker<java.util.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 java.lang.Comparable<? super T>> void writeForcedChunkOwners(java.util.Map<java.lang.String,it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundNBT>> forcedEntries, ForgeChunkManager.TicketTracker<T> tracker, java.lang.String listKey, int listType, java.util.function.BiConsumer<T,ListNBT> ownerWriter)
-
writeForcedChunkOwners
private static <T extends java.lang.Comparable<? super T>> void writeForcedChunkOwners(java.util.Map<java.lang.String,it.unimi.dsi.fastutil.longs.Long2ObjectMap<CompoundNBT>> forcedEntries, java.util.Map<ForgeChunkManager.TicketOwner<T>,it.unimi.dsi.fastutil.longs.LongSet> forcedChunks, java.lang.String listKey, int listType, java.util.function.BiConsumer<T,ListNBT> ownerWriter)
-
readForgeForcedChunks
public static void readForgeForcedChunks(CompoundNBT nbt, ForgeChunkManager.TicketTracker<BlockPos> blockForcedChunks, ForgeChunkManager.TicketTracker<java.util.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(java.lang.String modId, long chunkPos, CompoundNBT modEntry, java.lang.String key, java.util.Map<ForgeChunkManager.TicketOwner<BlockPos>,it.unimi.dsi.fastutil.longs.LongSet> blockForcedChunks)
Reads the forge block forced chunks.
-
readEntityForcedChunks
private static void readEntityForcedChunks(java.lang.String modId, long chunkPos, CompoundNBT modEntry, java.lang.String key, java.util.Map<ForgeChunkManager.TicketOwner<java.util.UUID>,it.unimi.dsi.fastutil.longs.LongSet> entityForcedChunks)
Reads the forge entity forced chunks.
-
-