Querz / NBT

A java implementation of the NBT protocol, including a way to implement custom tags.
MIT License
182 stars 48 forks source link

Selective/partial chunk loading #48

Open prydin opened 4 years ago

prydin commented 4 years ago

Some applications, like mappers, benefit from caching chunks and regions locally. However, a fully loaded region can take up significant space in memory, which limits the usefulness of caches.

I'm proposing a mechanism for loading only the portions of a chunk or region that an application intends to use. Then, the internal reference to data in the chunks could be released to allow it to be garbage collected.

I propose something like this:

MCAFile::public void deserialize(RandomAccessFile raf, int fieldFlags) throws IOException

It would be used like this:

mca.deserialize(file, BLOCK_IDS|HEIGHTMAPS|BLOCKLIGHT);

A chunk loaded this way cannot be written to disk and any attempt to do so should throw an exception.

If this seems OK, I will prepare a PR with the changes.