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 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 int(package private) 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 Supplier<DimensionDataStorage> private final List<ChunkGenerationTask> private final it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap<ChunkHolder> private final PlayerMapprivate final PoiManagerprivate final RandomStateprivate intprivate final Stringprivate final TicketStorage(package private) 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 as, but immutable for access from other threads.invalid reference
#loadedChunksprivate final WorldGenContextprivate final ChunkTaskDispatcherFields inherited from class net.minecraft.world.level.chunk.storage.ChunkStorage
fixerUpper, LAST_MONOLYTH_STRUCTURE_DATA_VERSION -
Constructor Summary
ConstructorsConstructorDescriptionChunkMap(ServerLevel pLevel, LevelStorageSource.LevelStorageAccess pStorageSource, com.mojang.datafixers.DataFixer pFixerUpper, StructureTemplateManager pStructureManager, Executor pDispatcher, BlockableEventLoop<Runnable> pMainThreadExecutor, LightChunkGetter pLightChunk, ChunkGenerator pGenerator, ChunkStatusUpdateListener pChunkStatusListener, Supplier<DimensionDataStorage> pOverworldDataStorage, TicketStorage pTicketStorage, int pServerViewDistance, boolean pSync) -
Method Summary
Modifier and TypeMethodDescriptionacquireGeneration(long p_347661_) protected void(package private) Stream<ChunkHolder> allChunksWithAtLeastStatus(ChunkStatus pStatus) (package private) booleananyPlayerCloseEnoughForSpawning(ChunkPos pChunkPos) private booleananyPlayerCloseEnoughForSpawningInternal(ChunkPos pChunkPos) private voidapplyChunkTrackingView(ServerPlayer pPlayer, ChunkTrackingView pChunkTrackingView) applyStep(GenerationChunkHolder p_347627_, ChunkStep p_347638_, StaticCache2D<GenerationChunkHolder> p_347552_) voidclose()(package private) void(package private) voidcollectSpawningChunks(List<LevelChunk> pOutput) private ChunkAccesscreateEmptyChunk(ChunkPos pChunkPos) debugFuturesAndCreateReportedException(IllegalStateException pException, String pDetails) private static voiddropChunk(ServerPlayer pPlayer, ChunkPos pChunkPos) (package private) voiddumpChunks(Writer pWriter) private static doubleeuclideanDistanceSquared(ChunkPos pChunkPos, Vec3 pPos) (package private) voidforEachBlockTickingChunk(Consumer<LevelChunk> pAction) voidforEachEntityTrackedBy(ServerPlayer pPlayer, Consumer<Entity> pAction) voidforEachReadyToSendChunk(Consumer<LevelChunk> pAction) protected ChunkGeneratorprotected ChunkGeneratorStructureStategetChunkDebugData(ChunkPos pPos) protected IntSuppliergetChunkQueueLevel(long pChunkPos) (package private) CompletableFuture<ChunkResult<List<ChunkAccess>>> getChunkRangeFuture(ChunkHolder pChunkHolder, int pRange, IntFunction<ChunkStatus> pStatusGetter) getChunkToSend(long pChunkPos) getLatestStatus(long pChunkPos) protected ThreadedLevelLightEnginegetPlayers(ChunkPos p_183801_, boolean p_183802_) Returns the players tracking the given chunk.getPlayersCloseForSpawning(ChunkPos pChunkPos) getPlayersWatching(Entity entity) (package private) intgetPlayerViewDistance(ServerPlayer pPlayer) protected PoiManagergetUpdatingChunkIfPresent(long pChunkPos) getVisibleChunkIfPresent(long pChunkPos) private ChunkAccesshandleChunkLoadFailure(Throwable pException, ChunkPos pChunkPos) booleanhasWork()private booleanisChunkOnTrackedBorder(ServerPlayer pPlayer, int pX, int pZ) Checks if a chunk is on the edge of the player's view distance.booleanisChunkTracked(ServerPlayer pPlayer, int pX, int pZ) Checks if a chunk is within a player's view distance.private booleanisExistingChunkFull(ChunkPos pChunkPos) booleanisTrackedByAnyPlayer(Entity pEntity) private static voidmarkChunkPendingToSend(ServerPlayer pPlayer, LevelChunk pChunk) private voidmarkChunkPendingToSend(ServerPlayer pPlayer, ChunkPos pChunkPos) private bytemarkPosition(ChunkPos pChunkPos, ChunkType pChunkType) private voidmarkPositionReplaceable(ChunkPos pChunkPos) voidmove(ServerPlayer pPlayer) private voidonChunkReadyToSend(ChunkHolder pChunkHolder, LevelChunk pChunk) (package private) voidonFullChunkStatusChange(ChunkPos pChunkPos, FullChunkStatus pFullChunkStatus) private voidonLevelChange(ChunkPos pChunkPos, IntSupplier pQueueLevelGetter, int pTicketLevel, IntConsumer pQueueLevelSetter) private booleanplayerIsCloseEnoughForSpawning(ServerPlayer pPlayer, ChunkPos pChunkPos) prepareAccessibleChunk(ChunkHolder pChunk) prepareEntityTickingChunk(ChunkHolder pChunk) prepareTickingChunk(ChunkHolder pHolder) private static StringprintFuture(CompletableFuture<ChunkResult<LevelChunk>> pFuture) private voidprocessUnloads(BooleanSupplier pHasMoreTime) protected booleanprotected RandomStateprivate CompletableFuture<Optional<CompoundTag>> voidreleaseGeneration(GenerationChunkHolder p_347698_) protected voidremoveEntity(Entity pEntity) voidresendBiomesForChunks(List<ChunkAccess> pChunks) private voidvoidprivate booleansave(ChunkAccess pChunk) protected voidsaveAllChunks(boolean pFlush) private booleansaveChunkIfNeeded(ChunkHolder pChunk, long pGametime) private voidsaveChunksEagerly(BooleanSupplier pHasMoreTime) private CompletableFuture<ChunkAccess> scheduleChunkLoad(ChunkPos pChunkPos) scheduleGenerationTask(ChunkStatus p_347605_, ChunkPos p_347675_) voidscheduleOnMainThreadMailbox(Runnable runnable) Neo: PR #937 This is for mainly pre-generation usage such as Neoforge's generate command.private voidscheduleUnload(long pChunkPos, ChunkHolder pChunkHolder) voidsendToTrackingPlayers(Entity pEntity, Packet<? super ClientGamePacketListener> pPacket) protected voidsendToTrackingPlayersAndSelf(Entity pEntity, Packet<? super ClientGamePacketListener> pPacket) voidsendToTrackingPlayersFiltered(Entity pEntity, Packet<? super ClientGamePacketListener> pPacket, Predicate<ServerPlayer> pFilter) private voidsetChunkUnsaved(ChunkPos pChunkPos) protected voidsetServerViewDistance(int pViewDistance) intsize()private booleanskipPlayer(ServerPlayer pPlayer) protected voidtick()protected voidtick(BooleanSupplier pHasMoreTime) (package private) ChunkHolderupdateChunkScheduling(long pChunkPos, int pNewLevel, ChunkHolder pHolder, int pOldLevel) Sets level and loads/unloads chunk.private voidupdateChunkTracking(ServerPlayer pPlayer) private voidupdatePlayerPos(ServerPlayer pPlayer) (package private) voidupdatePlayerStatus(ServerPlayer pPlayer, boolean pTrack) private CompoundTagupgradeChunkTag(CompoundTag pTag) voidwaitForLightBeforeSending(ChunkPos pChunkPos, int pRange) 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:
-
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 as, but immutable for access from other threads. This should never be mutated.invalid reference
#loadedChunks -
pendingUnloads
-
pendingGenerationTasks
-
level
-
lightEngine
-
mainThreadExecutor
-
randomState
-
chunkGeneratorState
-
overworldDataStorage
-
ticketStorage
-
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 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 pLevel, LevelStorageSource.LevelStorageAccess pStorageSource, com.mojang.datafixers.DataFixer pFixerUpper, StructureTemplateManager pStructureManager, Executor pDispatcher, BlockableEventLoop<Runnable> pMainThreadExecutor, LightChunkGetter pLightChunk, ChunkGenerator pGenerator, ChunkStatusUpdateListener pChunkStatusListener, Supplier<DimensionDataStorage> pOverworldDataStorage, TicketStorage pTicketStorage, int pServerViewDistance, boolean pSync)
-
-
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 pChunkHolder, int pRange, IntFunction<ChunkStatus> pStatusGetter) -
debugFuturesAndCreateReportedException
public ReportedException debugFuturesAndCreateReportedException(IllegalStateException pException, String pDetails) -
prepareEntityTickingChunk
-
updateChunkScheduling
@Nullable ChunkHolder updateChunkScheduling(long pChunkPos, int pNewLevel, @Nullable ChunkHolder pHolder, int pOldLevel) Sets level and loads/unloads chunk.- Parameters:
pHolder- TheChunkHolderof the chunk if it is loaded, and null otherwise.
-
onLevelChange
private void onLevelChange(ChunkPos pChunkPos, IntSupplier pQueueLevelGetter, int pTicketLevel, IntConsumer pQueueLevelSetter) -
close
- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classChunkStorage- Throws:
IOException
-
saveAllChunks
protected void saveAllChunks(boolean pFlush) -
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 p_347627_, ChunkStep p_347638_, StaticCache2D<GenerationChunkHolder> p_347552_) - 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 pViewDistance) -
getPlayerViewDistance
-
markChunkPendingToSend
-
markChunkPendingToSend
-
dropChunk
-
getChunkToSend
-
size
public int size() -
getDistanceManager
-
dumpChunks
- Throws:
IOException
-
printFuture
-
readChunk
-
upgradeChunkTag
-
collectSpawningChunks
-
forEachBlockTickingChunk
-
anyPlayerCloseEnoughForSpawning
-
collectForceTickingChunks
-
anyPlayerCloseEnoughForSpawningInternal
-
getPlayersCloseForSpawning
-
playerIsCloseEnoughForSpawning
-
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 pEntity, Packet<? super ClientGamePacketListener> pPacket, Predicate<ServerPlayer> pFilter) -
sendToTrackingPlayersAndSelf
protected void sendToTrackingPlayersAndSelf(Entity pEntity, Packet<? super ClientGamePacketListener> pPacket) -
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(it.unimi.dsi.fastutil.longs.LongList)as an example usage of this method.
-