title: How do I edit .mca files from Minecraft?
body: <h1>Introduction</h1>
  
  <p>I want to combine my separate Minecraft worlds into a single world and it seemed like a relatively easy feat, but as I did research it evolved into the need to make a custom program.</p>
  
  <h2>The Struggle</h2>
  
  <p>I started by shifting the region files and combining them in one region folder, which seemed like the obvious solution and it almost worked. <strong>Note: I've opened the files and it seems entire sectors have their coordinates stored, not entities, hence the terrain itself is spatially mismatched with the region file name.</strong></p>
  
  <p>That led to quite a bit of lag when I opened the client and the regions failed to render. I read up on the Anvil file format and imagined a scheme for reading NBT files. I figured I could manually read out the bytes and edit them, but in my continued research I got conflicting answers as to whether region files are gzipped.</p>
  
  <p>I finished enough code to read some raw bytes, but the byte values didn't come out as I expected.</p>
  
  <p>According to the info I have on NBT files, they all start with a CompoundTag and a CompoundTag starts as a single byte valued as 10, or x0A.
  This is where I got my format information: <a href="https://minecraft.gamepedia.com/NBT_format" rel="nofollow noreferrer">https://minecraft.gamepedia.com/NBT_format</a></p>
  
  <p>Here's a screenshot of what actually came out:</p>
  
  <p><a href="https://i.stack.imgur.com/de1Fe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/de1Fe.png" alt="Byte-reading code in Java and Output"></a></p>
  
  <p><em>Note: The class description in the screenshot is not accurate. I just quickly filled in enough to read the bytes, not flesh out the UI function.</em></p>
  
  <p>I assume these bytes coming out as non-sense is a sign that the file is compressed. I found this as a start to the gzip problem:
  <a href="http://gnuwin32.sourceforge.net/packages/gzip.htm" rel="nofollow noreferrer">http://gnuwin32.sourceforge.net/packages/gzip.htm</a></p>
  
  <p>I imagine if I could get this installed it would unzip this .mca file and I could read the bytes as expected, but I don't understand the installation instructions. It says use the "Shell Commands, 'configure', 'make' and 'make install'". To me that sounds like Unix, but the file I downloaded is for Windows? There aren't any exe's, but there are quite a few C files. I don't have a C-compiler. . .</p>
  
  <p>Note: I still have not got the gzip software to work.</p>
  
  <h3>Post Script</h3>
  
  <p>I've seen similar questions asked here, but all of them were either old (2016ish) with dead links to software that used to work, or they were recent and unanswered. I found one specific copy of this question asked 5 months ago, but I had to make an account to comment. Here's the link: <a href="https://stackoverflow.com/questions/57397934/how-can-read-minecraft-mca-files-so-that-in-python-i-can-extract-individual-blo">How can read Minecraft .mca files so that in python I can extract individual blocks?</a> His question is with regard to a Python implementation. He said he found an NBT library for Python, but it was rejecting his MCA files for being <em>not-gzipped</em>.</p>
  
  <p>I've got a lead on understanding the problem because I have the NBTExplorer source code (see the answer I posted), but I'll have to update on how that pans out. As far as getting my world fixed, I think I have a viable solution now.</p>
  
  <p>If anyone could point me to a finished Java library, with source code, that opens .mca's or a discussion board related to this topic that'd be cool. I'm still also interested in how file compression works, but that's probably outside this question's scope. I realize this isn't directly bug or error related; <strike>it's</strike> it was moreso that I didn't know what further steps to take to make a code that accomplishes this task.</p>
  
  <h2>Update</h2>
  
  <p>I found someone else's program to do this and posted it as an answer, but I'd still like to know how the file is converted from bytes to useable info. Using the manual edit method of the answer I posted, I will need at most <strong>241,664 manual edits</strong>, so I still need a better solution.</p>