Class ChunkMap
java.lang.Object
net.minecraft.world.level.chunk.storage.SimpleRegionStorage
net.minecraft.server.level.ChunkMap
- All Implemented Interfaces:
AutoCloseable, ChunkHolder.PlayerProvider, GeneratingChunkMap
public class ChunkMap
extends SimpleRegionStorage
implements ChunkHolder.PlayerProvider, GeneratingChunkMap
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerprivate static final intprivate static final intprivate static final byteprivate static final byteprivate static final byteprivate final ChunkGeneratorStructureStateprivate final ChunkStatusUpdateListenerprivate final it.unimi.dsi.fastutil.longs.LongSetprivate final it.unimi.dsi.fastutil.longs.Long2ByteMapprivate final ChunkMap.DistanceManagerprivate static final intprivate final it.unimi.dsi.fastutil.ints.Int2ObjectMap<ChunkMap.TrackedEntity> static final intprivate final ServerLevelprivate final ThreadedLevelLightEngineprivate final ChunkTaskDispatcherprivate static final org.slf4j.Loggerprivate final BlockableEventLoop<Runnable> private static final intstatic final intstatic final intprivate booleanTrue if changes have been made toand thus a new copy of the collection has to be made intoinvalid reference
#loadedChunks.invalid reference
#immutableLoadedChunksprivate final it.unimi.dsi.fastutil.longs.Long2LongMapprivate final List<ChunkGenerationTask> private final it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap<ChunkHolder> private final PlayerMapprivate final PoiManagerprivate final RandomStateprivate intprivate final Stringprivate final TicketStorageprivate final it.unimi.dsi.fastutil.longs.LongSetChunks that have been requested to be unloaded, but haven't been unloaded yet.private static final CompletableFuture<ChunkResult<List<ChunkAccess>>> private static final ChunkResult<List<ChunkAccess>> private final it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap<ChunkHolder> Chunks in memory.private it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap<ChunkHolder> Same asupdatingChunkMap, but immutable for access from other threads.private final WorldGenContextprivate final ChunkTaskDispatcher -
Constructor Summary
ConstructorsConstructorDescriptionChunkMap(ServerLevel level, LevelStorageSource.LevelStorageAccess levelStorage, com.mojang.datafixers.DataFixer dataFixer, StructureTemplateManager structureManager, Executor executor, BlockableEventLoop<Runnable> mainThreadExecutor, LightChunkGetter chunkGetter, ChunkGenerator generator, ChunkStatusUpdateListener chunkStatusListener, Supplier<SavedDataStorage> overworldDataStorage, TicketStorage ticketStorage, int serverViewDistance, boolean syncWrites) -
Method Summary
Modifier and TypeMethodDescriptionacquireGeneration(long chunkNode) protected void(package private) Stream<ChunkHolder> (package private) booleanprivate boolean(package private) booleananyPlayerCloseEnoughTo(BlockPos pos, int maxDistance) private voidapplyChunkTrackingView(ServerPlayer player, ChunkTrackingView next) applyStep(GenerationChunkHolder chunkHolder, ChunkStep step, StaticCache2D<GenerationChunkHolder> cache) voidclose()(package private) voidcollectSpawningChunks(List<LevelChunk> output) private ChunkAccesscreateEmptyChunk(ChunkPos pos) debugFuturesAndCreateReportedException(IllegalStateException exception, String details) private static voiddropChunk(ServerPlayer player, ChunkPos pos) (package private) voiddumpChunks(Writer output) private static doubleeuclideanDistanceSquared(ChunkPos chunkPos, Vec3 pos) (package private) voidforEachBlockTickingChunk(Consumer<LevelChunk> tickingChunkConsumer) voidforEachEntityTrackedBy(ServerPlayer player, Consumer<Entity> consumer) voidforEachReadyToSendChunk(Consumer<LevelChunk> consumer) protected ChunkGeneratorprotected ChunkGeneratorStructureStatestatic CompoundTaggetChunkDataFixContextTag(ResourceKey<Level> dimension, Optional<Identifier> generatorIdentifier) protected IntSuppliergetChunkQueueLevel(long pos) (package private) CompletableFuture<ChunkResult<List<ChunkAccess>>> getChunkRangeFuture(ChunkHolder centerChunk, int range, IntFunction<ChunkStatus> distanceToStatus) @Nullable LevelChunkgetChunkToSend(long key) @Nullable ChunkStatusgetLatestStatus(long key) protected ThreadedLevelLightEnginegetPlayers(ChunkPos pos, boolean borderOnly) Returns the players tracking the given chunk.getPlayersWatching(Entity entity) private intgetPlayerViewDistance(ServerPlayer player) protected PoiManager@Nullable ChunkHoldergetUpdatingChunkIfPresent(long key) @Nullable ChunkHoldergetVisibleChunkIfPresent(long key) private ChunkAccesshandleChunkLoadFailure(Throwable throwable, ChunkPos pos) booleanhasWork()private booleanisChunkOnTrackedBorder(ServerPlayer player, int chunkX, int chunkZ) Checks if a chunk is on the edge of the player's view distance.booleanisChunkTracked(ServerPlayer player, int chunkX, int chunkZ) Checks if a chunk is within a player's view distance.private booleanbooleanisTrackedByAnyPlayer(Entity entity) private static voidmarkChunkPendingToSend(ServerPlayer player, LevelChunk chunk) private voidmarkChunkPendingToSend(ServerPlayer player, ChunkPos pos) private bytemarkPosition(ChunkPos pos, ChunkType type) private voidvoidmove(ServerPlayer player) private voidonChunkReadyToSend(ChunkHolder chunkHolder, LevelChunk chunk) (package private) voidonFullChunkStatusChange(ChunkPos pos, FullChunkStatus status) private voidonLevelChange(ChunkPos pos, IntSupplier oldLevel, int newLevel, IntConsumer setQueueLevel) private booleanplayerIsCloseEnoughForSpawning(ServerPlayer player, ChunkPos pos) private booleanplayerIsCloseEnoughTo(ServerPlayer player, Vec3 pos, int maxDistance) prepareTickingChunk(ChunkHolder chunk) private static StringprintFuture(CompletableFuture<ChunkResult<LevelChunk>> future) private voidprocessUnloads(BooleanSupplier haveTime) protected booleanprotected RandomStateprivate CompletableFuture<Optional<CompoundTag>> voidreleaseGeneration(GenerationChunkHolder chunkHolder) protected voidremoveEntity(Entity entity) voidresendBiomesForChunks(List<ChunkAccess> chunks) private voidvoidprivate booleansave(ChunkAccess chunk) protected voidsaveAllChunks(boolean flushStorage) private booleansaveChunkIfNeeded(ChunkHolder chunk, long now) private voidsaveChunksEagerly(BooleanSupplier haveTime) private CompletableFuture<ChunkAccess> scheduleGenerationTask(ChunkStatus targetStatus, ChunkPos pos) voidscheduleOnMainThreadMailbox(Runnable runnable) Neo: PR #937 This is for mainly pre-generation usage such as Neoforge's generate command.private voidscheduleUnload(long pos, ChunkHolder chunkHolder) voidsendToTrackingPlayers(Entity entity, Packet<? super ClientGamePacketListener> packet) protected voidsendToTrackingPlayersAndSelf(Entity entity, Packet<? super ClientGamePacketListener> packet) voidsendToTrackingPlayersFiltered(Entity entity, Packet<? super ClientGamePacketListener> packet, Predicate<ServerPlayer> targetPredicate) private voidsetChunkUnsaved(ChunkPos chunkPos) protected voidsetServerViewDistance(int newViewDistance) intsize()private booleanskipPlayer(ServerPlayer player) protected voidtick()protected voidtick(BooleanSupplier haveTime) private @Nullable ChunkHolderupdateChunkScheduling(long node, int level, @Nullable ChunkHolder chunk, int oldLevel) Sets level and loads/unloads chunk.private voidupdateChunkTracking(ServerPlayer player) private voidupdatePlayerPos(ServerPlayer player) (package private) voidupdatePlayerStatus(ServerPlayer player, boolean added) private CompoundTagvoidwaitForLightBeforeSending(ChunkPos centerChunk, int chunkRadius) Methods inherited from class SimpleRegionStorage
chunkScanner, injectDatafixingContext, isOldChunkAround, read, storageInfo, synchronize, upgradeChunkTag, upgradeChunkTag, upgradeChunkTag, write, write
-
Field Details
-
UNLOADED_CHUNK_LIST_RESULT
-
UNLOADED_CHUNK_LIST_FUTURE
-
CHUNK_TYPE_REPLACEABLE
private static final byte CHUNK_TYPE_REPLACEABLE- See Also:
-
CHUNK_TYPE_UNKNOWN
private static final byte CHUNK_TYPE_UNKNOWN- See Also:
-
CHUNK_TYPE_FULL
private static final byte CHUNK_TYPE_FULL- See Also:
-
LOGGER
private static final org.slf4j.Logger LOGGER -
CHUNK_SAVED_PER_TICK
private static final int CHUNK_SAVED_PER_TICK- See Also:
-
CHUNK_SAVED_EAGERLY_PER_TICK
private static final int CHUNK_SAVED_EAGERLY_PER_TICK- See Also:
-
EAGER_CHUNK_SAVE_COOLDOWN_IN_MILLIS
private static final int EAGER_CHUNK_SAVE_COOLDOWN_IN_MILLIS- See Also:
-
MAX_ACTIVE_CHUNK_WRITES
private static final int MAX_ACTIVE_CHUNK_WRITES- See Also:
-
MIN_VIEW_DISTANCE
public static final int MIN_VIEW_DISTANCE- See Also:
-
MAX_VIEW_DISTANCE
public static final int MAX_VIEW_DISTANCE- See Also:
-
FORCED_TICKET_LEVEL
public static final int FORCED_TICKET_LEVEL -
updatingChunkMap
private final it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap<ChunkHolder> updatingChunkMapChunks in memory. This should only ever be manipulated by the main thread. -
visibleChunkMap
private volatile it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap<ChunkHolder> visibleChunkMapSame asupdatingChunkMap, but immutable for access from other threads. This should never be mutated. -
pendingUnloads
-
pendingGenerationTasks
-
level
-
lightEngine
-
mainThreadExecutor
-
randomState
-
chunkGeneratorState
-
ticketStorage
-
poiManager
-
toDrop
private final it.unimi.dsi.fastutil.longs.LongSet toDropChunks that have been requested to be unloaded, but haven't been unloaded yet. -
modified
private boolean modifiedTrue if changes have been made toand thus a new copy of the collection has to be made intoinvalid reference
#loadedChunks.invalid reference
#immutableLoadedChunks -
worldgenTaskDispatcher
-
lightTaskDispatcher
-
chunkStatusListener
-
distanceManager
-
storageName
-
playerMap
-
entityMap
-
chunkTypeCache
private final it.unimi.dsi.fastutil.longs.Long2ByteMap chunkTypeCache -
nextChunkSaveTime
private final it.unimi.dsi.fastutil.longs.Long2LongMap nextChunkSaveTime -
chunksToEagerlySave
private final it.unimi.dsi.fastutil.longs.LongSet chunksToEagerlySave -
unloadQueue
-
activeChunkWrites
-
serverViewDistance
private int serverViewDistance -
worldGenContext
-
-
Constructor Details
-
ChunkMap
public ChunkMap(ServerLevel level, LevelStorageSource.LevelStorageAccess levelStorage, com.mojang.datafixers.DataFixer dataFixer, StructureTemplateManager structureManager, Executor executor, BlockableEventLoop<Runnable> mainThreadExecutor, LightChunkGetter chunkGetter, ChunkGenerator generator, ChunkStatusUpdateListener chunkStatusListener, Supplier<SavedDataStorage> overworldDataStorage, TicketStorage ticketStorage, int serverViewDistance, boolean syncWrites)
-
-
Method Details
-
setChunkUnsaved
-
generator
-
generatorState
-
randomState
-
isChunkTracked
Checks if a chunk is within a player's view distance. -
isChunkOnTrackedBorder
Checks if a chunk is on the edge of the player's view distance. -
getLightEngine
-
getUpdatingChunkIfPresent
-
getVisibleChunkIfPresent
-
getLatestStatus
-
getChunkQueueLevel
-
getChunkDebugData
-
getChunkRangeFuture
CompletableFuture<ChunkResult<List<ChunkAccess>>> getChunkRangeFuture(ChunkHolder centerChunk, int range, IntFunction<ChunkStatus> distanceToStatus) -
debugFuturesAndCreateReportedException
public ReportedException debugFuturesAndCreateReportedException(IllegalStateException exception, String details) -
prepareEntityTickingChunk
-
updateChunkScheduling
private @Nullable ChunkHolder updateChunkScheduling(long node, int level, @Nullable ChunkHolder chunk, int oldLevel) Sets level and loads/unloads chunk.- Parameters:
chunk- TheChunkHolderof the chunk if it is loaded, and null otherwise.
-
onLevelChange
private void onLevelChange(ChunkPos pos, IntSupplier oldLevel, int newLevel, IntConsumer setQueueLevel) -
close
- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classSimpleRegionStorage- Throws:
IOException
-
saveAllChunks
protected void saveAllChunks(boolean flushStorage) -
tick
-
hasWork
public boolean hasWork() -
processUnloads
-
saveChunksEagerly
-
scheduleUnload
-
promoteChunkMap
protected boolean promoteChunkMap() -
scheduleChunkLoad
-
handleChunkLoadFailure
-
createEmptyChunk
-
markPositionReplaceable
-
markPosition
-
acquireGeneration
- Specified by:
acquireGenerationin interfaceGeneratingChunkMap
-
releaseGeneration
- Specified by:
releaseGenerationin interfaceGeneratingChunkMap
-
applyStep
public CompletableFuture<ChunkAccess> applyStep(GenerationChunkHolder chunkHolder, ChunkStep step, StaticCache2D<GenerationChunkHolder> cache) - Specified by:
applyStepin interfaceGeneratingChunkMap
-
scheduleGenerationTask
- Specified by:
scheduleGenerationTaskin interfaceGeneratingChunkMap
-
runGenerationTask
-
runGenerationTasks
public void runGenerationTasks()- Specified by:
runGenerationTasksin interfaceGeneratingChunkMap
-
prepareTickingChunk
-
onChunkReadyToSend
-
prepareAccessibleChunk
-
allChunksWithAtLeastStatus
-
saveChunkIfNeeded
-
save
-
isExistingChunkFull
-
setServerViewDistance
protected void setServerViewDistance(int newViewDistance) -
getPlayerViewDistance
-
markChunkPendingToSend
-
markChunkPendingToSend
-
dropChunk
-
getChunkToSend
-
size
public int size() -
getDistanceManager
-
dumpChunks
- Throws:
IOException
-
printFuture
-
readChunk
-
upgradeChunkTag
-
getChunkDataFixContextTag
public static CompoundTag getChunkDataFixContextTag(ResourceKey<Level> dimension, Optional<Identifier> generatorIdentifier) -
collectSpawningChunks
-
forEachBlockTickingChunk
-
anyPlayerCloseEnoughForSpawning
-
anyPlayerCloseEnoughTo
-
anyPlayerCloseEnoughForSpawningInternal
-
getPlayersCloseForSpawning
-
playerIsCloseEnoughForSpawning
-
playerIsCloseEnoughTo
-
euclideanDistanceSquared
-
skipPlayer
-
updatePlayerStatus
-
updatePlayerPos
-
move
-
updateChunkTracking
-
applyChunkTrackingView
-
getPlayers
Description copied from interface:ChunkHolder.PlayerProviderReturns the players tracking the given chunk.- Specified by:
getPlayersin interfaceChunkHolder.PlayerProvider
-
addEntity
-
removeEntity
-
tick
protected void tick() -
sendToTrackingPlayers
-
sendToTrackingPlayersFiltered
public void sendToTrackingPlayersFiltered(Entity entity, Packet<? super ClientGamePacketListener> packet, Predicate<ServerPlayer> targetPredicate) -
sendToTrackingPlayersAndSelf
protected void sendToTrackingPlayersAndSelf(Entity entity, Packet<? super ClientGamePacketListener> packet) -
isTrackedByAnyPlayer
-
forEachEntityTrackedBy
-
resendBiomesForChunks
-
getPoiManager
-
getStorageName
-
onFullChunkStatusChange
-
waitForLightBeforeSending
-
forEachReadyToSendChunk
-
getPlayersWatching
-
scheduleOnMainThreadMailbox
Neo: PR #937 This is for mainly pre-generation usage such as Neoforge's generate command. Use this to schedule chunk load tasks into ChunkTaskPriorityQueueSorter so a chunk is fully finished all of their tasks before scheduling more chunks to load. Reason for this is when scheduling a huge ton of Full Status chunk tasks to the server (to load chunks), you could cause the server to only process those loading tasks and never reach the two chunk tasks that are automatically scheduled to run after the chunk is loaded to Full. As a result of flooding the system with Full Status chunk tasks, the queue for the two kind of successor chunk tasks will grow and become a memory leak of lambdas and chunk references. Use this method to schedule tasks for loading chunks in your whenCompleteAsync method call so the tasks gets processed properly over time and not leak. SeeGenerationTask.enqueueChunks(LongList)as an example usage of this method.
-