Class RegionFile

java.lang.Object
net.minecraft.world.level.chunk.storage.RegionFile
All Implemented Interfaces:
AutoCloseable

public class RegionFile extends Object implements AutoCloseable
This class handles a single region (or anvil) file and all files for single chunks at chunk positions for that one region file.
  • Field Details

  • Constructor Details

  • Method Details

    • getPath

      public Path getPath()
    • getExternalChunkPath

      private Path getExternalChunkPath(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.
    • getChunkDataInputStream

      @Nullable public DataInputStream getChunkDataInputStream(ChunkPos pChunkPos) throws IOException
      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

      private static ByteArrayInputStream createStream(ByteBuffer pSourceBuffer, int pLength)
    • 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 one int.
    • 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

      public boolean doesChunkExist(ChunkPos pChunkPos)
    • getChunkDataOutputStream

      public DataOutputStream getChunkDataOutputStream(ChunkPos pChunkPos) throws IOException
      Creates a new InputStream for a chunk stored in a separate file.
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Throws:
      IOException
    • clear

      public void clear(ChunkPos pChunkPos) throws IOException
      Throws:
      IOException
    • write

      protected void write(ChunkPos pChunkPos, ByteBuffer pChunkData) throws IOException
      Throws:
      IOException
    • createExternalStub

      private ByteBuffer 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

      private void writeHeader() throws IOException
      Throws:
      IOException
    • getOffset

      private int getOffset(ChunkPos pChunkPos)
    • hasChunk

      public boolean hasChunk(ChunkPos pChunkPos)
    • getOffsetIndex

      private static int getOffsetIndex(ChunkPos pChunkPos)
      Gets the offset within the region file where the chunk metadata for a chunk can be found.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
    • padToFullSector

      private void padToFullSector() throws IOException
      Throws:
      IOException