Lymkwi / python-minetest

A python library to manipulate minetest's files
6 stars 3 forks source link

help with a script #3

Closed ghost closed 8 years ago

ghost commented 8 years ago

I have made a script that tries to load the contents of an image into the map.sqlite but am getting stuck on line 626 of map.py throwing an error. I am only just starting to play with your library so maybe I am misunderstanding the usage. I have tried this with a fresh map.sqlite from a new world, and have also tried emptying the contents of the blocks table with an sqlite manager tool, same error... the script is at https://gist.github.com/bobombolo/d243ccf2d03224d10cab traceback:

D:\minetest\minetest-0.4.13\python-minetest\src>python demo_map_preloading.py ..
\..\worlds\b\map.sqlite ..\..\mods\realterrain\rasters\dem.bmp
2016-03-29 12:55:11,578 map:set_maxcachesize         :576  DEBUG    MapVessel's
maximum cache size set to 100
2016-03-29 12:55:11,592 map:load_mapblock            :589  DEBUG    Loaded mapbl
ock at -637489152.0
Traceback (most recent call last):
  File "demo_map_preloading.py", line 52, in 
    db.set_node(pos, node)
  File "D:\minetest\minetest-0.4.13\python-minetest\src\map.py", line 626, in se
t_node
    raise IgnoreContentReplacementError("Pos: " + str(pos))
errors.IgnoreContentReplacementError: Pos: (0, 185, -600)
Lymkwi commented 8 years ago

This error is thrown if you try to load a mapblock that has never been generated. Your only solution is to catch the Exception and initiate an empty mapblock using MapInterface.init_mapblock(mapblockpos, override=False). You don't really need to set the override parameter since it only prevents the function from creating an empty mapblock where a generated mapblock exists.

ghost commented 8 years ago

I added a line for init_mapblock, see the gist, now I am getting an error:

D:\minetest\minetest-0.4.13\python-minetest\src>python demo_map_preloading.py ..
\..\worlds\b\map.sqlite ..\..\mods\realterrain\rasters\dem.bmp
2016-03-29 14:36:29,842 map:set_maxcachesize         :576  DEBUG    MapVessel's
maximum cache size set to 100
Traceback (most recent call last):
  File "demo_map_preloading.py", line 53, in 
    db.init_mapblock(mapblockpos, override=True)
  File "D:\minetest\minetest-0.4.13\python-minetest\src\map.py", line 712, in in
it_mapblock
    res = self.interface.load(mapblockpos)
  File "D:\minetest\minetest-0.4.13\python-minetest\src\map.py", line 526, in lo
ad
    if not self.cache.get(blockID):
TypeError: unhashable instance
Lymkwi commented 8 years ago

You need to give an integer represention of the mapblock's position to init_mapblock. I'll add assertations to check types so that those errors appear obvious. I'll also start writing documentation.

mapblock = libminetest.utils.intFromPos(libminetest.map.determineMapBlock(pos), 4096)