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.cppTo 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.cppYour 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.cppSo I just have to figure this out...