HELP: minetest .sqlite format

dgm5555
Member
 
Posts: 244
Joined: Tue Apr 08, 2014 19:45

HELP: minetest .sqlite format

by dgm5555 » Thu Feb 05, 2015 23:43

I want to create a converter from minecraft worlds to minetest. I have found python code which can extract information from minecraft anvil and mcregion format files (which is way above my head, but I figure can be used with some very basic modification - see another post starting to break this down - https://forum.minetest.net/viewtopic.php?f=5&t=11146.
I've read the minetest file format page: https://github.com/minetest/minetest/blob/master/doc/mapformat.txt

And I have no idea what it means...
not even the faintest idea of how to even start generating the header stuff...
:'(
Can anyone help? Essentially I want to develop python code which can create a 'naked' minetest map.sqlite file which just needs the node information from minecraft injected into it.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: HELP: minetest .sqlite format

by rubenwardy » Fri Feb 06, 2015 08:38

Use the sqlite library in python and create the tables using SQL statements. There is a CREATE TABLE that you need to run in the file format file.

The blob is just binary data, one value after another.
 

dgm5555
Member
 
Posts: 244
Joined: Tue Apr 08, 2014 19:45

Re: HELP: minetest .sqlite format

by dgm5555 » Fri Feb 06, 2015 21:44

Ha, that much even I get. It's the magicHappens section that I really don't understand (but I am figuring out).

Soooo...
In the beginning there was a table and that table was called "blocks"
And lo, inside blocks were contained two columns called 'pos' and 'data'
And it was a good and sensible(ish) structure
(the bit that isn't sensible is that most builders call the individual building blocks of minetest either blocks, nodes, or sometimes voxels
However 'block' also refer to groups of nodes (also called mapBlocks, sectors or chunks)
mapBlocks are chunks of 16x16x16 nodes
)

And pos (an int) was the primary index key
https://github.com/minetest/minetest/blob/master/src/database.cpp

To get pos if you know the x,y,z coordinates of a chunk use:-
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
p = {X=xCoord, Y=yCoord, Z=zCoord}

def getBlockAsInteger(p):
    return int64(p.Z*16777216 + p.Y*4096 + p.X)

def int64(u):
    while u >= 2**63:
        u -= 2**64
    while u <= -2**63:
        u += 2**64
    return u


to get x,y,z if you know the pos (="go the other way")

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
def getIntegerAsBlock(i):
    x = unsignedToSigned(i % 4096, 2048)
    i = int((i - x) / 4096)
    y = unsignedToSigned(i % 4096, 2048)
    i = int((i - y) / 4096)
    z = unsignedToSigned(i % 4096, 2048)
    return x,y,z

def unsignedToSigned(i, max_positive):
    if i < max_positive:
        return i
    else:
        return i - 2*max_positive


data (a blob) contains everything else. a blob is a variable sized binary format data storage unit, which stores data about a 16x16x16 chunk of nodes.
https://github.com/minetest/minetest/blob/master/src/mapblock.cpp
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
MapBlock:
The following assumes map format version >= 24:
u8 refers to an 8-bit byte, 0x refers to a bit within the byte
u16 is a 16 bit byte

u8 version
u8 flags
- 0x01: is_underground
- 0x02: day_night_differs
- 0x04: lighting_expired
- 0x08: generated
u8 content_width    # Number of bytes in the content (param0) fields of nodes
u8 params_width     # Number of bytes used for parameters per node

Now comes the node data (which is zlib-compressed)
- The location of a node in each of those arrays is (z*16*16 + y*16 + x).
u16[4096]: param0   # The content id of a node
u8[4096]: param1    # use varies with node type
u8[4096]: param2    # use varies with node type

Now comes meta-data (which is zlib-compressed)
u16 version         # (always=1)
u16 count           # of metadata
foreach count:
    u16 position (p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X)
    u16 type_id
    u16 content_size
    u8[content_size]    # array containing the actual metadata
   
Then comes more bits and bobs (timers,timestamp, etc)
...
[EOF]   terminates the blob


To put it in or get it out call
magicHappensIn(allTheLittleRandomBitsOfData)
return blob

magicHappensOut(blob)
return allTheLittleRandomBitsOfData

magicHappens() still needs some consideration. However the source code which serialises the data is in https://github.com/minetest/minetest/blob/master/src/mapblock.cpp
So I just have to figure this out...
 

User avatar
lag01
Member
 
Posts: 190
Joined: Sun Mar 16, 2014 03:41
GitHub: AndrejIT
IRC: lag01
In-game: lag

Re: HELP: minetest .sqlite format

by lag01 » Mon Mar 14, 2016 18:38

I got one step further in this matter and split this "magic blob" in little smaller parts. But it is still far from manipulating individual nodes and especially their metadata.
viewtopic.php?f=14&t=10333
 

ptvirgo
Member
 
Posts: 18
Joined: Thu May 26, 2016 22:18
GitHub: ptvirgo

Re: HELP: minetest .sqlite format

by ptvirgo » Thu May 26, 2016 22:28

Did you manage to sort out the nodes? I'm also trying to convert the block data into something a person could actually read; interpreting the bytes from the available documentation is proving a challenge.
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 10 guests

cron