public class ForgeChunkManager
extends java.lang.Object
setForcedChunkLoadingCallback(Object, LoadingCallback)
2. Mods ask for a ticket requestTicket(Object, World, Type)
and then hold on to that ticket.
3. Mods request chunks to stay loaded forceChunk(Ticket, ChunkPos)
or remove chunks from force loading unforceChunk(Ticket, ChunkPos)
.
4. When a world unloads, the tickets associated with that world are saved by the chunk manager.
5. When a world loads, saved tickets are offered to the mods associated with the tickets. The ForgeChunkManager.Ticket.getModData()
that is set by the mod should be used to re-register
chunks to stay loaded (and maybe take other actions).
The chunkloading is configurable at runtime. The file "config/forgeChunkLoading.cfg" contains both default configuration for chunkloading, and a sample individual mod
specific override section.Modifier and Type | Class and Description |
---|---|
private static class |
ForgeChunkManager.ChunkEntry |
static class |
ForgeChunkManager.ForceChunkEvent |
static interface |
ForgeChunkManager.LoadingCallback
All mods requiring chunkloading need to implement this to handle the
re-registration of chunk tickets at world loading time
|
static interface |
ForgeChunkManager.OrderedLoadingCallback
This is a special LoadingCallback that can be implemented as well as the
LoadingCallback to provide access to additional behaviour.
|
static interface |
ForgeChunkManager.PlayerOrderedLoadingCallback |
static class |
ForgeChunkManager.Ticket |
static class |
ForgeChunkManager.Type |
static class |
ForgeChunkManager.UnforceChunkEvent |
Modifier and Type | Field and Description |
---|---|
static boolean |
asyncChunkLoading |
private static java.util.Map<java.lang.String,ForgeChunkManager.LoadingCallback> |
callbacks |
private static java.io.File |
cfgFile |
private static java.util.Map<java.lang.String,java.lang.Integer> |
chunkConstraints |
private static Configuration |
config |
private static int |
defaultMaxChunks |
private static int |
defaultMaxCount |
private static java.util.Map<World,com.google.common.cache.Cache<java.lang.Long,ForgeChunkManager.ChunkEntry>> |
dormantChunkCache |
private static int |
dormantChunkCacheSize |
private static java.util.Map<World,com.google.common.collect.ImmutableSetMultimap<ChunkPos,ForgeChunkManager.Ticket>> |
forcedChunks |
static java.util.List<java.lang.String> |
MOD_PROP_ORDER |
private static boolean |
overridesEnabled |
private static com.google.common.collect.BiMap<java.util.UUID,ForgeChunkManager.Ticket> |
pendingEntities |
private static int |
playerTicketLength |
private static com.google.common.collect.SetMultimap<java.lang.String,ForgeChunkManager.Ticket> |
playerTickets |
private static java.util.Map<java.lang.String,java.lang.Integer> |
ticketConstraints |
private static java.util.Map<World,com.google.common.collect.Multimap<java.lang.String,ForgeChunkManager.Ticket>> |
tickets |
private static java.util.Set<java.lang.String> |
warnedMods |
Constructor and Description |
---|
ForgeChunkManager() |
Modifier and Type | Method and Description |
---|---|
static void |
addConfigProperty(java.lang.Object mod,
java.lang.String propertyName,
java.lang.String value,
Property.Type type) |
(package private) static void |
captureConfig(java.io.File configDir) |
static Chunk |
fetchDormantChunk(long coords,
World world) |
static void |
forceChunk(ForgeChunkManager.Ticket ticket,
ChunkPos chunk)
Force the supplied chunk coordinate to be loaded by the supplied ticket.
|
static Configuration |
getConfig() |
static ConfigCategory |
getConfigFor(java.lang.Object mod) |
private static ModContainer |
getContainer(java.lang.Object mod) |
static ConfigCategory |
getDefaultsCategory() |
static int |
getMaxChunkDepthFor(java.lang.String modId) |
static int |
getMaxTicketLengthFor(java.lang.String modId) |
static java.util.List<ConfigCategory> |
getModCategories() |
static com.google.common.collect.ImmutableSetMultimap<ChunkPos,ForgeChunkManager.Ticket> |
getPersistentChunksFor(World world)
The list of persistent chunks in the world.
|
static java.util.Iterator<Chunk> |
getPersistentChunksIterableFor(World world,
java.util.Iterator<Chunk> chunkIterator) |
private static void |
loadChunkEntities(Chunk chunk,
NBTTagCompound nbt,
World world) |
(package private) static void |
loadConfiguration() |
(package private) static void |
loadEntity(Entity entity) |
(package private) static void |
loadWorld(World world) |
static void |
putDormantChunk(long coords,
Chunk chunk) |
static void |
releaseTicket(ForgeChunkManager.Ticket ticket)
Release the ticket back to the system.
|
static void |
reorderChunk(ForgeChunkManager.Ticket ticket,
ChunkPos chunk)
Reorganize the internal chunk list so that the chunk supplied is at the *end* of the list
This helps if you wish to guarantee a certain "automatic unload ordering" for the chunks
in the ticket list
|
static ForgeChunkManager.Ticket |
requestPlayerTicket(java.lang.Object mod,
java.lang.String player,
World world,
ForgeChunkManager.Type type) |
static ForgeChunkManager.Ticket |
requestTicket(java.lang.Object mod,
World world,
ForgeChunkManager.Type type)
Request a chunkloading ticket of the appropriate type for the supplied mod
|
static boolean |
savedWorldHasForcedChunkTickets(java.io.File chunkDir)
Allows dynamically loading world mods to test if there are chunk tickets in the world
Mods that add dynamically generated worlds (like Mystcraft) should call this method
to determine if the world should be loaded during server starting.
|
(package private) static void |
saveWorld(World world) |
static void |
setForcedChunkLoadingCallback(java.lang.Object mod,
ForgeChunkManager.LoadingCallback callback)
Set a chunkloading callback for the supplied mod object
|
static void |
storeChunkNBT(Chunk chunk,
NBTTagCompound nbt) |
static void |
syncConfigDefaults()
Synchronizes the local fields with the values in the Configuration object.
|
static int |
ticketCountAvailableFor(java.lang.Object mod,
World world)
Discover the available tickets for the mod in the world
|
static int |
ticketCountAvailableFor(java.lang.String username) |
static void |
unforceChunk(ForgeChunkManager.Ticket ticket,
ChunkPos chunk)
Unforce the supplied chunk, allowing it to be unloaded and stop ticking.
|
(package private) static void |
unloadWorld(World world) |
private static int defaultMaxCount
private static int defaultMaxChunks
private static boolean overridesEnabled
private static java.util.Map<World,com.google.common.collect.Multimap<java.lang.String,ForgeChunkManager.Ticket>> tickets
private static java.util.Map<java.lang.String,java.lang.Integer> ticketConstraints
private static java.util.Map<java.lang.String,java.lang.Integer> chunkConstraints
private static com.google.common.collect.SetMultimap<java.lang.String,ForgeChunkManager.Ticket> playerTickets
private static java.util.Map<java.lang.String,ForgeChunkManager.LoadingCallback> callbacks
private static java.util.Map<World,com.google.common.collect.ImmutableSetMultimap<ChunkPos,ForgeChunkManager.Ticket>> forcedChunks
private static com.google.common.collect.BiMap<java.util.UUID,ForgeChunkManager.Ticket> pendingEntities
private static java.util.Map<World,com.google.common.cache.Cache<java.lang.Long,ForgeChunkManager.ChunkEntry>> dormantChunkCache
private static java.io.File cfgFile
private static Configuration config
private static int playerTicketLength
private static int dormantChunkCacheSize
public static boolean asyncChunkLoading
public static final java.util.List<java.lang.String> MOD_PROP_ORDER
private static java.util.Set<java.lang.String> warnedMods
public static java.util.Iterator<Chunk> getPersistentChunksIterableFor(World world, java.util.Iterator<Chunk> chunkIterator)
public static boolean savedWorldHasForcedChunkTickets(java.io.File chunkDir)
chunkDir
- The chunk directory to test: should be equivalent to WorldServer.getChunkSaveLocation()
static void loadWorld(World world)
static void unloadWorld(World world)
public static void setForcedChunkLoadingCallback(java.lang.Object mod, ForgeChunkManager.LoadingCallback callback)
mod
- The mod instance registering the callbackcallback
- The code to call back when forced chunks are loadedpublic static int ticketCountAvailableFor(java.lang.Object mod, World world)
mod
- The mod that will own the ticketsworld
- The worldprivate static ModContainer getContainer(java.lang.Object mod)
public static int getMaxTicketLengthFor(java.lang.String modId)
public static int getMaxChunkDepthFor(java.lang.String modId)
public static int ticketCountAvailableFor(java.lang.String username)
@Nullable public static ForgeChunkManager.Ticket requestPlayerTicket(java.lang.Object mod, java.lang.String player, World world, ForgeChunkManager.Type type)
@Nullable public static ForgeChunkManager.Ticket requestTicket(java.lang.Object mod, World world, ForgeChunkManager.Type type)
mod
- The mod requesting a ticketworld
- The world in which it is requesting the tickettype
- The type of ticketpublic static void releaseTicket(ForgeChunkManager.Ticket ticket)
ticket
- The ticket to releasepublic static void forceChunk(ForgeChunkManager.Ticket ticket, ChunkPos chunk)
ForgeChunkManager.Ticket.maxDepth
is exceeded, the least
recently registered chunk is unforced and may be unloaded.
It is safe to force the chunk several times for a ticket, it will not generate duplication or change the ordering.ticket
- The ticket registering the chunkchunk
- The chunk to forcepublic static void reorderChunk(ForgeChunkManager.Ticket ticket, ChunkPos chunk)
ticket
- The ticket holding the chunk listchunk
- The chunk you wish to push to the end (so that it would be unloaded last)public static void unforceChunk(ForgeChunkManager.Ticket ticket, ChunkPos chunk)
ticket
- The ticket holding the chunkchunk
- The chunk to unforcestatic void loadConfiguration()
public static com.google.common.collect.ImmutableSetMultimap<ChunkPos,ForgeChunkManager.Ticket> getPersistentChunksFor(World world)
world
- static void saveWorld(World world)
static void loadEntity(Entity entity)
public static void putDormantChunk(long coords, Chunk chunk)
public static void storeChunkNBT(Chunk chunk, NBTTagCompound nbt)
private static void loadChunkEntities(Chunk chunk, NBTTagCompound nbt, World world)
static void captureConfig(java.io.File configDir)
public static void syncConfigDefaults()
public static Configuration getConfig()
public static ConfigCategory getDefaultsCategory()
public static java.util.List<ConfigCategory> getModCategories()
@Nullable public static ConfigCategory getConfigFor(java.lang.Object mod)
public static void addConfigProperty(java.lang.Object mod, java.lang.String propertyName, java.lang.String value, Property.Type type)