Immersive Paintings [Fabric/Forge]

Immersive Paintings [Fabric/Forge]

3M Downloads

How can I parse the .dat file inside the ./world/data/ folder?

Urufusan opened this issue ยท 3 comments

commented

While migrating a (fabric) singleplayer world to a multiplayer (fabric) server, I've noticed that the painting storing system is different. I noticed that you can transfer images over to the server by extracting immersive_paintings.dat (because it acts as a gzip archive) and then reading the raw file inside using hex edit to get the raw text for the image locations and cache names. I tried writing a parser, but I didn't have enough success with that and couldn't find how the dat file system works inside the source code. These are some examples of my tests. I would appreciate an elaboration on how the mod's dat files work (so i can parse them using a proper script) and eventually commit my migration tool to the /scripts/ folder inside the repo.

Images:

  • Hex editor screenshot (trying to figure out the escape sequences for new lines)

image

  • Output of the half-working parser

image

  • Parser code
# coding: utf-8
import string
import re

def load_text_file(file_path):
    filtered_text = ""
    with open(file_path, 'r', encoding='utf-8', errors='ignore') as file:
        for line in file:
            filtered_line = ""
            for char in line:
                #if char.isalnum() or char in string.punctuation or char == '\n':
                if char.isalnum() or char in string.punctuation or char == ' ' or char == '\n':
                    filtered_line += char
                else:
                    filtered_line += "|"
            filtered_text += filtered_line
    return filtered_text

def simplify_text(text):
    # Replace consecutive "|" symbols with a single "|"
    text = re.sub(r'\|+', '|', text)

    # Replace consecutive spaces with a single space
    text = re.sub(r' +', ' ', text)

    return text

def write_to_file(string, filename):
    with open(filename, 'w') as file:
        file.write(string)

# Example usage
file_path = 'immersive_paintings'
filtered_text = load_text_file(file_path)
write_to_file(str(simplify_text(filtered_text)),'convotest.txt')
commented

This is weird, the painting storing system on an MP server is very clear, while the singleplayer dat file is very hard to work with. Maybe I missed something related to the functionality of the .dat file?

commented

I'm an idiot, this is just NBT; I will close the issue for now, I'm sorry for any interruptions I've might've caused.

commented

Yep, those use the persistent save system of vanilla Minecraft, which is a NBT under the hood. It's interesting that you found differences between SP and MP and forge and fabric, it should be the same.