Class RegionFile
java.lang.Object
net.minecraft.world.level.chunk.storage.RegionFile
- All Implemented Interfaces:
AutoCloseable
This class handles a single region (or anvil) file and all files for single chunks at chunk positions for that one region file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class(package private) static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate static final intprivate static final Stringprivate static final intprivate final Pathprivate final FileChannelprivate final ByteBufferprivate static final int(package private) final RegionStorageInfoprivate static final org.slf4j.Loggerprivate final IntBufferprivate static final ByteBufferprivate final Pathprivate static final intprotected static final intprivate final IntBufferprotected final RegionBitmap(package private) final RegionFileVersion -
Constructor Summary
ConstructorsConstructorDescriptionRegionFile(RegionStorageInfo pInfo, Path pPath, Path pExternalFileDir, boolean pSync) RegionFile(RegionStorageInfo pInfo, Path pPath, Path pExternalFileDir, RegionFileVersion pVersion, boolean pSync) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose()private DataInputStreamcreateChunkInputStream(ChunkPos pChunkPos, byte pVersionByte, InputStream pInputStream) private DataInputStreamcreateExternalChunkInputStream(ChunkPos pChunkPos, byte pVersionByte) private ByteBufferprivate static ByteArrayInputStreamcreateStream(ByteBuffer pSourceBuffer, int pLength) booleandoesChunkExist(ChunkPos pChunkPos) voidflush()getChunkDataInputStream(ChunkPos pChunkPos) getChunkDataOutputStream(ChunkPos pChunkPos) Creates a newInputStreamfor a chunk stored in a separate file.private PathgetExternalChunkPath(ChunkPos pChunkPos) Gets the path to store a chunk that can not be stored within the region file because it's larger than 1 MiB.private static bytegetExternalChunkVersion(byte pVersionByte) private static intgetNumSectors(int pPackedSectorOffset) Gets the amount of 4 KiB sectors used to store a chunk.private intprivate static intgetOffsetIndex(ChunkPos pChunkPos) Gets the offset within the region file where the chunk metadata for a chunk can be found.getPath()private static intgetSectorNumber(int pPackedSectorOffset) Gets the offset in 4 KiB sectors from the start of the region file, where the data for a chunk starts.private static intbooleanprivate static booleanisExternalStreamChunk(byte pVersionByte) private intpackSectorOffset(int pSectorOffset, int pSectorCount) Packs the offset in 4 KiB sectors from the region file start and the amount of 4 KiB sectors used to store a chunk into oneint.private voidprivate static intsizeToSectors(int pSize) Gets the amount of sectors required to store chunk data of a certain size in bytes.protected voidwrite(ChunkPos pChunkPos, ByteBuffer pChunkData) private voidprivate RegionFile.CommitOpwriteToExternalFile(Path pExternalChunkFile, ByteBuffer pChunkData) Writes a chunk to a separate file with only that chunk.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
SECTOR_BYTES
private static final int SECTOR_BYTES- See Also:
-
SECTOR_INTS
protected static final int SECTOR_INTS- See Also:
-
CHUNK_HEADER_SIZE
private static final int CHUNK_HEADER_SIZE- See Also:
-
HEADER_OFFSET
private static final int HEADER_OFFSET- See Also:
-
PADDING_BUFFER
-
EXTERNAL_FILE_EXTENSION
- See Also:
-
EXTERNAL_STREAM_FLAG
private static final int EXTERNAL_STREAM_FLAG- See Also:
-
EXTERNAL_CHUNK_THRESHOLD
private static final int EXTERNAL_CHUNK_THRESHOLD- See Also:
-
CHUNK_NOT_PRESENT
private static final int CHUNK_NOT_PRESENT- See Also:
-
info
-
path
-
file
-
externalFileDir
-
version
-
header
-
offsets
-
timestamps
-
usedSectors
-
-
Constructor Details
-
RegionFile
public RegionFile(RegionStorageInfo pInfo, Path pPath, Path pExternalFileDir, boolean pSync) throws IOException - Throws:
IOException
-
RegionFile
public RegionFile(RegionStorageInfo pInfo, Path pPath, Path pExternalFileDir, RegionFileVersion pVersion, boolean pSync) throws IOException - Throws:
IOException
-
-
Method Details
-
getPath
-
getExternalChunkPath
Gets the path to store a chunk that can not be stored within the region file because it's larger than 1 MiB. -
getChunkDataInputStream
- Throws:
IOException
-
getTimestamp
private static int getTimestamp() -
isExternalStreamChunk
private static boolean isExternalStreamChunk(byte pVersionByte) -
getExternalChunkVersion
private static byte getExternalChunkVersion(byte pVersionByte) -
createChunkInputStream
@Nullable private DataInputStream createChunkInputStream(ChunkPos pChunkPos, byte pVersionByte, InputStream pInputStream) throws IOException - Throws:
IOException
-
createExternalChunkInputStream
@Nullable private DataInputStream createExternalChunkInputStream(ChunkPos pChunkPos, byte pVersionByte) throws IOException - Throws:
IOException
-
createStream
-
packSectorOffset
private int packSectorOffset(int pSectorOffset, int pSectorCount) Packs the offset in 4 KiB sectors from the region file start and the amount of 4 KiB sectors used to store a chunk into oneint. -
getNumSectors
private static int getNumSectors(int pPackedSectorOffset) Gets the amount of 4 KiB sectors used to store a chunk. -
getSectorNumber
private static int getSectorNumber(int pPackedSectorOffset) Gets the offset in 4 KiB sectors from the start of the region file, where the data for a chunk starts. -
sizeToSectors
private static int sizeToSectors(int pSize) Gets the amount of sectors required to store chunk data of a certain size in bytes. -
doesChunkExist
-
getChunkDataOutputStream
Creates a newInputStreamfor a chunk stored in a separate file.- Throws:
IOException
-
flush
- Throws:
IOException
-
clear
- Throws:
IOException
-
write
- Throws:
IOException
-
createExternalStub
-
writeToExternalFile
private RegionFile.CommitOp writeToExternalFile(Path pExternalChunkFile, ByteBuffer pChunkData) throws IOException Writes a chunk to a separate file with only that chunk. This is used for chunks larger than 1 MiB- Throws:
IOException
-
writeHeader
- Throws:
IOException
-
getOffset
-
hasChunk
-
getOffsetIndex
Gets the offset within the region file where the chunk metadata for a chunk can be found. -
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
padToFullSector
- Throws:
IOException
-