Package net.minecraft.server.level
Class ChunkMap
java.lang.Object
net.minecraft.world.level.chunk.storage.ChunkStorage
net.minecraft.server.level.ChunkMap
- All Implemented Interfaces:
AutoCloseable
,ChunkHolder.PlayerProvider
,GeneratingChunkMap
public class ChunkMap
extends ChunkStorage
implements ChunkHolder.PlayerProvider, GeneratingChunkMap
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
(package private) class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final byte
private static final byte
private static final byte
private final ChunkGeneratorStructureState
private final it.unimi.dsi.fastutil.longs.Long2LongMap
private final ChunkStatusUpdateListener
private final it.unimi.dsi.fastutil.longs.Long2ByteMap
private final ChunkMap.DistanceManager
private static final int
private final it.unimi.dsi.fastutil.ints.Int2ObjectMap
<ChunkMap.TrackedEntity> static final int
(package private) final ServerLevel
private final ThreadedLevelLightEngine
private static final org.slf4j.Logger
private final BlockableEventLoop
<Runnable> private final ProcessorHandle
<ChunkTaskPriorityQueueSorter.Message<Runnable>> static final int
static final int
private boolean
True if changes have been made toinvalid reference
#loadedChunks
invalid reference
#immutableLoadedChunks
private final Supplier
<DimensionDataStorage> private final List
<ChunkGenerationTask> private final it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap
<ChunkHolder> private final PlayerMap
private final PoiManager
private final ChunkProgressListener
private final ChunkTaskPriorityQueueSorter
private final RandomState
private int
private final String
private final AtomicInteger
(package private) final it.unimi.dsi.fastutil.longs.LongSet
Chunks 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 asinvalid reference
#loadedChunks
private final WorldGenContext
private final ProcessorHandle
<ChunkTaskPriorityQueueSorter.Message<Runnable>> Fields inherited from class net.minecraft.world.level.chunk.storage.ChunkStorage
fixerUpper, LAST_MONOLYTH_STRUCTURE_DATA_VERSION
-
Constructor Summary
ConstructorsConstructorDescriptionChunkMap
(ServerLevel level, LevelStorageSource.LevelStorageAccess levelStorageAccess, com.mojang.datafixers.DataFixer fixerUpper, StructureTemplateManager structureManager, Executor dispatcher, BlockableEventLoop<Runnable> mainThreadExecutor, LightChunkGetter lightChunk, ChunkGenerator generator, ChunkProgressListener progressListener, ChunkStatusUpdateListener chunkStatusListener, Supplier<DimensionDataStorage> overworldDataStorage, int viewDistance, boolean sync) -
Method Summary
Modifier and TypeMethodDescriptionacquireGeneration
(long chunkPos) protected void
(package private) boolean
anyPlayerCloseEnoughForSpawning
(ChunkPos chunkPos) private void
applyChunkTrackingView
(ServerPlayer player, ChunkTrackingView chunkTrackingView) applyStep
(GenerationChunkHolder chunk, ChunkStep step, StaticCache2D<GenerationChunkHolder> cache) void
protected void
broadcastAndSend
(Entity entity, Packet<?> packet) void
close()
private ChunkAccess
createEmptyChunk
(ChunkPos chunkPos) debugFuturesAndCreateReportedException
(IllegalStateException exception, String details) private static void
dropChunk
(ServerPlayer player, ChunkPos chunkPos) (package private) void
dumpChunks
(Writer writer) private static double
euclideanDistanceSquared
(ChunkPos chunkPos, Entity entity) Returns the squared distance to the center of the chunk.protected ChunkGenerator
protected ChunkGeneratorStructureState
protected IntSupplier
getChunkQueueLevel
(long chunkPos) private CompletableFuture
<ChunkResult<List<ChunkAccess>>> getChunkRangeFuture
(ChunkHolder chunkHolder, int range, IntFunction<ChunkStatus> statusGetter) protected Iterable
<ChunkHolder> getChunkToSend
(long chunkPos) protected ThreadedLevelLightEngine
getPlayers
(ChunkPos pos, boolean boundaryOnly) Returns the players tracking the given chunk.getPlayersCloseForSpawning
(ChunkPos chunkPos) (package private) int
getPlayerViewDistance
(ServerPlayer player) protected PoiManager
int
protected ChunkHolder
getUpdatingChunkIfPresent
(long chunkPos) getVisibleChunkIfPresent
(long chunkPos) private ChunkAccess
handleChunkLoadFailure
(Throwable exception, ChunkPos chunkPos) boolean
hasWork()
private static boolean
private boolean
isChunkOnTrackedBorder
(ServerPlayer player, int x, int z) Checks if a chunk is on the edge of the player's view distance.(package private) boolean
isChunkTracked
(ServerPlayer player, int x, int z) Checks if a chunk is within a player's view distance.private boolean
isExistingChunkFull
(ChunkPos chunkPos) private static void
markChunkPendingToSend
(ServerPlayer player, LevelChunk chunk) private void
markChunkPendingToSend
(ServerPlayer player, ChunkPos chunkPos) private byte
markPosition
(ChunkPos chunkPos, ChunkType chunkType) private void
markPositionReplaceable
(ChunkPos chunkPos) void
move
(ServerPlayer player) private void
onChunkReadyToSend
(LevelChunk chunk) (package private) void
onFullChunkStatusChange
(ChunkPos chunkPos, FullChunkStatus fullChunkStatus) private boolean
playerIsCloseEnoughForSpawning
(ServerPlayer player, ChunkPos chunkPos) prepareAccessibleChunk
(ChunkHolder holder) prepareTickingChunk
(ChunkHolder holder) private static String
printFuture
(CompletableFuture<ChunkResult<LevelChunk>> future) private void
processUnloads
(BooleanSupplier hasMoreTime) protected boolean
protected RandomState
private CompletableFuture
<Optional<CompoundTag>> void
protected void
removeEntity
(Entity entity) void
resendBiomesForChunks
(List<ChunkAccess> chunks) private void
void
private boolean
save
(ChunkAccess chunk) protected void
saveAllChunks
(boolean flush) private boolean
saveChunkIfNeeded
(ChunkHolder holder) private CompletableFuture
<ChunkAccess> scheduleChunkLoad
(ChunkPos chunkPos) scheduleGenerationTask
(ChunkStatus targetStatus, ChunkPos pos) void
Neo: PR #937 This is for mainly pre-generation usage such as Neoforge's generate command.private void
scheduleUnload
(long chunkPos, ChunkHolder chunkHolder) protected void
setServerViewDistance
(int viewDistance) int
size()
private boolean
skipPlayer
(ServerPlayer player) protected void
tick()
protected void
tick
(BooleanSupplier hasMoreTime) (package private) ChunkHolder
updateChunkScheduling
(long chunkPos, int newLevel, ChunkHolder holder, int oldLevel) Sets level and loads/unloads chunk.private void
updateChunkTracking
(ServerPlayer player) private void
updatePlayerPos
(ServerPlayer player) (package private) void
updatePlayerStatus
(ServerPlayer player, boolean track) private CompoundTag
void
waitForLightBeforeSending
(ChunkPos chunkPos, int range) Methods inherited from class net.minecraft.world.level.chunk.storage.ChunkStorage
chunkScanner, flushWorker, getVersion, handleLegacyStructureIndex, injectDatafixingContext, isOldChunkAround, read, storageInfo, upgradeChunkTag, 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:
-
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 asinvalid reference
#loadedChunks
-
pendingUnloads
-
pendingGenerationTasks
-
level
-
lightEngine
-
mainThreadExecutor
-
randomState
-
chunkGeneratorState
-
overworldDataStorage
-
poiManager
-
toDrop
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 toinvalid reference
#loadedChunks
invalid reference
#immutableLoadedChunks
-
queueSorter
-
worldgenMailbox
-
mainThreadMailbox
-
progressListener
-
chunkStatusListener
-
distanceManager
-
tickingGenerated
-
storageName
-
playerMap
-
entityMap
-
chunkTypeCache
private final it.unimi.dsi.fastutil.longs.Long2ByteMap chunkTypeCache -
chunkSaveCooldowns
private final it.unimi.dsi.fastutil.longs.Long2LongMap chunkSaveCooldowns -
unloadQueue
-
serverViewDistance
private int serverViewDistance -
worldGenContext
-
-
Constructor Details
-
ChunkMap
public ChunkMap(ServerLevel level, LevelStorageSource.LevelStorageAccess levelStorageAccess, com.mojang.datafixers.DataFixer fixerUpper, StructureTemplateManager structureManager, Executor dispatcher, BlockableEventLoop<Runnable> mainThreadExecutor, LightChunkGetter lightChunk, ChunkGenerator generator, ChunkProgressListener progressListener, ChunkStatusUpdateListener chunkStatusListener, Supplier<DimensionDataStorage> overworldDataStorage, int viewDistance, boolean sync)
-
-
Method Details
-
generator
-
generatorState
-
randomState
-
euclideanDistanceSquared
Returns the squared distance to the center of the chunk. -
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
-
getChunkQueueLevel
-
getChunkDebugData
-
getChunkRangeFuture
private CompletableFuture<ChunkResult<List<ChunkAccess>>> getChunkRangeFuture(ChunkHolder chunkHolder, int range, IntFunction<ChunkStatus> statusGetter) -
debugFuturesAndCreateReportedException
public ReportedException debugFuturesAndCreateReportedException(IllegalStateException exception, String details) -
prepareEntityTickingChunk
-
updateChunkScheduling
@Nullable ChunkHolder updateChunkScheduling(long chunkPos, int newLevel, @Nullable ChunkHolder holder, int oldLevel) Sets level and loads/unloads chunk.- Parameters:
holder
- TheChunkHolder
of the chunk if it is loaded, and null otherwise.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classChunkStorage
- Throws:
IOException
-
saveAllChunks
protected void saveAllChunks(boolean flush) -
tick
-
hasWork
public boolean hasWork() -
processUnloads
-
scheduleUnload
-
promoteChunkMap
protected boolean promoteChunkMap() -
scheduleChunkLoad
-
isChunkDataValid
-
handleChunkLoadFailure
-
createEmptyChunk
-
markPositionReplaceable
-
markPosition
-
acquireGeneration
- Specified by:
acquireGeneration
in interfaceGeneratingChunkMap
-
releaseGeneration
- Specified by:
releaseGeneration
in interfaceGeneratingChunkMap
-
applyStep
public CompletableFuture<ChunkAccess> applyStep(GenerationChunkHolder chunk, ChunkStep step, StaticCache2D<GenerationChunkHolder> cache) - Specified by:
applyStep
in interfaceGeneratingChunkMap
-
scheduleGenerationTask
- Specified by:
scheduleGenerationTask
in interfaceGeneratingChunkMap
-
runGenerationTask
-
runGenerationTasks
public void runGenerationTasks()- Specified by:
runGenerationTasks
in interfaceGeneratingChunkMap
-
prepareTickingChunk
-
onChunkReadyToSend
-
prepareAccessibleChunk
-
getTickingGenerated
public int getTickingGenerated() -
saveChunkIfNeeded
-
save
-
isExistingChunkFull
-
setServerViewDistance
protected void setServerViewDistance(int viewDistance) -
getPlayerViewDistance
-
markChunkPendingToSend
-
markChunkPendingToSend
-
dropChunk
-
getChunkToSend
-
size
public int size() -
getDistanceManager
-
getChunks
-
dumpChunks
- Throws:
IOException
-
printFuture
-
readChunk
-
upgradeChunkTag
-
anyPlayerCloseEnoughForSpawning
-
getPlayersCloseForSpawning
-
playerIsCloseEnoughForSpawning
-
skipPlayer
-
updatePlayerStatus
-
updatePlayerPos
-
move
-
updateChunkTracking
-
applyChunkTrackingView
-
getPlayers
Returns the players tracking the given chunk.- Specified by:
getPlayers
in interfaceChunkHolder.PlayerProvider
-
addEntity
-
removeEntity
-
tick
protected void tick() -
broadcast
-
broadcastAndSend
-
resendBiomesForChunks
-
getPoiManager
-
getStorageName
-
onFullChunkStatusChange
-
waitForLightBeforeSending
-
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(it.unimi.dsi.fastutil.longs.LongList)
as an example usage of this method.
-