Click here to Skip to main content
15,878,230 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
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: Chunk Format -[^] but it seemed to not work.

The question in more detail can be found here:

What I have tried:

1. 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)

2. 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
        return value & 0x0F

3. 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.
Updated 4-Jul-23 14:05pm
Richard MacCutchan 10-Jun-23 7:36am    
"Tried taking the HEX value of the bits and somehow convert it to a number."
The bits are already a number. A 4-bit field of 1010 is the numeric value 10, 0111 is 7, etc.
Ilai K 10-Jun-23 9:06am    
I meant for example the hex number: 0x34
I would take the 3 without the 4 or even just do 3+4 (just any kind of combination that might help)
Richard MacCutchan 10-Jun-23 9:10am    
I am not sure what you are referring to. If this is in relation to the palette data then that is explained in the Wiki.
Ilai K 10-Jun-23 10:14am    
Yes, I am talking about that. By the Wiki, you mean in here: ?
Because I tried that and it didn't really work, maybe I didn't do it correctly but there are some things in there I didn't understand that don't sound like proper English for example the sentence: "For a bits per block value of 15, the data is stored such that bits 1 through 15 are the first entry", Could you maybe explain it to me, or show me pesudo/python code for it?
Ill try to recreate it tomorrow (lost the code the last time I did it) and show it to you, maybe you'll be able to figure out whats wrong.
Richard MacCutchan 10-Jun-23 10:16am    
Sorry, I have never tried to use this feature so I cannot suggest any code. And the Wiki details would take me quite a long time to understand.

Share this answer
Oh dear. I'm working on the same thing and... it's pretty confusing and I've been coding for 30 years (although too much webby stuff for the last 20, my bitwise stuff is rusty).
I know that's not helpful, but you're not being dumb, this is confusing AND badly documented.
I have made a chunk with a palette of under 16 items and have 256 lots 64 bit ints. Fine. That makes sense...
I have a chunk with 33 items in the palette... forcing it up into 6 bits per item. Now I have 410 lots of 64 bit numbers... hmm. I'm gonna force a 5 bit palette.. and that give 342 lots of 64 bit ints..

OK. So the total *bits* needed for 5 bits *16*16*16*16 = 320 x 64 bits...

but aha! we can fit 12 x 5 bit numbers into one 64 bit numbers (with 4 wasted bits).
And 4096/12 = 341.333 (rounding up to 342... so that makes sense. Each 64 bit number has 5 bits of data).

OK, trying that on the 6 bit palette... we can fit 10 6 bit numbers into 64 (still with 4 bits wasted)... and 4096/10 = 409.6... so that explains the 410 ints in the 6 bit palette.

So that's a clue at least. I've still got to write code to deal with this horror show. I mean, why on earth is it like this? WHYYYY?
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900