First of all, hello everyone,

I'm currently making a program to read Minecraft region files (r.#.#.mca) for a server.
The problem I have is that I can't decompress them, I tried GZip and ZLib decompression but none of them worked. I already searched for solutions but there is little to no information online. It's really important that I find a solution to that issue.

Thanks in advance.

  • \$\begingroup\$ The docs say Zlib is what's used, so it sounds like you're on the right track. Can you give more details of what exactly you've tried (step by step) and in what particular way these approaches failed to work? \$\endgroup\$
    – DMGregory
    Aug 30 '16 at 11:26
  • \$\begingroup\$ Well, I first used the jnbt library as it provides methods to read NBT files but it expects gzipped files. When I tried to read region files it crashed and told me that the files weren't in GZip format. So, I then tried to use the Inflater class from the Java zip API because it uses the zlib algorithm. But this time it tells me "unknown compression method". That's where I am right now. \$\endgroup\$
    – Darmo
    Aug 30 '16 at 14:28
  • \$\begingroup\$ If I'm reading the docs correctly, it sounds like each block of "chunk" data in the file is Zlib compressed individually, not the .mca file as a whole. So you're going to need to start by parsing the chunk information tables to slice out each block of the file you want to decompress. Have you done that yet? \$\endgroup\$
    – DMGregory
    Aug 30 '16 at 14:37
  • \$\begingroup\$ Well, I didn't see that bit, I'm gonna try and see what I can do. \$\endgroup\$
    – Darmo
    Aug 30 '16 at 14:39
  • \$\begingroup\$ So, I tried my best but still not working. Out of all the files I've tested, none seemed to follow the format from the wiki page (MCRegion format). They say it has not changed since, but it seems it did anyway. I didn't find any information about the precise structure of .mca files. \$\endgroup\$
    – Darmo
    Aug 30 '16 at 15:33

So I found the AnvilChunkLoader class, copied its loadChunk__Async method and it worked.
This class can be found at net.minecraft.world.chunk.storage.AnvilChunkLoader for Minecraft 1.8.9
You have to find the method loadChunk__Async(World worldIn, int x, int z).
The part I needed was:

DataInputStream datainputstream = RegionFileCache.getChunkInputStream(chunkSaveLocation, x, z);
if (datainputstream == null) {
  return null;
NBTTagCompound tag = CompressedStreamTools.read(datainputstream);

To make it work, you need to specify the path to the region folder that contains the file, then the chunk coordinates x and z. The tag variable should contain the chunk data in NBT format.

  • 3
    \$\begingroup\$ This answer would be even better if you described where to find this class, or included a summary of the code you ended up using and how to work with it. The more information you share, the easier you make things for the next person to run into this problem the way you did. Try to write the documentation you wish you had when you started. ;) \$\endgroup\$
    – DMGregory
    Aug 30 '16 at 15:55
  • \$\begingroup\$ I can't before 2 days it says :/ \$\endgroup\$
    – Darmo
    Aug 30 '16 at 21:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .