How can I parse the .dat file inside the ./world/data/ folder?
Urufusan opened this issue ยท 3 comments
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)
- Output of the half-working parser
- 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')
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?
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.