classSource
public class RegionFile
implements CloseableReads Anvil region files (.mca) Format: 8192-byte header followed by chunk payloads, each compressed individually
- Implemented interfaces
- Closeable, AutoCloseable
Methods
void close()RegionFile create(File)Creates a new, empty region file (a zeroed 8192-byte header, no chunks)
and opens it.boolean hasChunk(int, int)RegionFile open(File)NbtCompound readChunk(int, int)void writeChunk(int, int, NbtCompound)Writes and serializes NBT data of the chunk into this region file,
at the specified sector position, for the provided chunk coordinates.public void close() throws IOException| Throws | ||
|---|---|---|
IOException | ||
Implements Closeable.close()
create(File)
staticSource
public static RegionFile create(File file) throws IOExceptionCreates a new, empty region file (a zeroed 8192-byte header, no chunks)
and opens it. Use this instead of open() if the .mca file doesn't exist yet,
e.g. the first time a chunk is written to a region that was not yet generated
| Parameters | ||
|---|---|---|
file | File | |
| Returns | ||
RegionFile | ||
| Throws | ||
IOException | ||
public boolean hasChunk(int chunkX, int chunkZ)| Parameters | ||
|---|---|---|
chunkX | int | |
chunkZ | int | |
| Returns | ||
boolean | ||
open(File)
staticSource
public static RegionFile open(File file) throws IOException| Parameters | ||
|---|---|---|
file | File | |
| Returns | ||
RegionFile | ||
| Throws | ||
IOException | ||
public NbtCompound readChunk(int chunkX, int chunkZ) throws IOException| Parameters | ||
|---|---|---|
chunkX | int | |
chunkZ | int | |
| Returns | ||
NbtCompound | ||
| Throws | ||
IOException | ||
public void writeChunk(int chunkX, int chunkZ, NbtCompound chunkData) throws IOExceptionWrites and serializes NBT data of the chunk into this region file,
at the specified sector position, for the provided chunk coordinates.
If the data is still able to fit in the chunk's previous sectors,
then these sectors are reused. Otherwise, sectors are appended to the end of the
file. Unused sectors, if the chunk is shrunk in size, remain in the file.
(Vanilla Minecraft behavior, defragmentation is not implemented.)
Data is always written with Zlib compression, even if the original chunk was
read with different compression. Updates header fields with location and timestamp.
| Parameters | ||
|---|---|---|
chunkX | int | |
chunkZ | int | |
chunkData | NbtCompound | |
| Throws | ||
IOException | If the serialized+compressed chunk needs more than 255 sectors (~1MB compressed), the region file format's own hard limit | |