Problem
I have a pretty technical question about Minecraft,
So I'm building a Minecraft server wrapper, and want to add an option to edit the world when the server is offline. That means messing with the save file. I have managed to make it work for 1.8 because the blocks were saved as a list of IDs, but in 1.19 the blocks are saved in a palette
(which I understand) and a data
array, I understand the data it stores (indices that point to the palette), But I don't understand how to extract (I was able to do it but only by copy-paste) and modify data in there. I really want to understand the mechanics behind it so I can do it myself, I am aware that there are other libs that do that but I want to learn how to do it myself.
I have tried different approaches, the most official one I tried is this wiki article but it seemed to not work.
Info
- Language:
Python
- Python Version:
3.9.8
- Desired Minecraft Version:
1.19
(1.15 too, but its a bit different) - Using NBTExplorer to view world data
- OS: Windows 10
Other tries
- Tried to take each 4 bits of a long and shift them 8 and 4 bits to the left or right (all combs didn't work)
- Tried taking 4 bits of each long and putting it inside a nibble function:
def nibble(byte_array, index):
value = byte_array[index // 2]
if index % 2:
return (value >> 4) &0x0F
else:
return value & 0x0F
- Tried taking the HEX value of the bits and somehow convert it to a number.
No approach from the above worked... P.S. If you need the code from the WIKI tell me, I couldn't find it but if you need it I'll write it again.
TLDR
Please explain to me the mechanics and logic behind the data
tag in the NBT of each section
under a chunk NBT data so I can extract and modify the indices in it (data
tag) using python for Minecraft versions 1.15-1.20
See data
To see the data I'm talking about for your-self you could install NBTExplorer and then open a world save file (%appdata%/.minecraft/saves/[world name]/region/[any region file]
), each region file in there is 32x32 chunks, drag-and-drop it into NBTExplorer, pick a chunk then go to section, then pick a section, go to block_states and there you'll be able to see the data
tag. That's the data I'm trying to decode, understand and modify.
Sources
These are sources I tried taking info from, there are more, but not useful ones.
- https://wiki.vg/Chunk_Format#Paletted_Container_structure
- https://minecraft.fandom.com/wiki/Chunk_format
- https://technical-minecraft.fandom.com/wiki/Chunk_Loading
Please answer in detail, and be patient with me. Thank you so much!
And of course any other information you might need to help me, feel free to ask!
NOTE: Please don't tell me there are libraries that do this I want to understand the logic and not just copy code, same for source code, if you find a resource or code online that might help me I'd like an explanation so could understand (If you don't know how it works but know that it works please point me to the exact code so I can attempt to understand myself)