[0.4.8] LuaVoxelManipulator
Posted: Fri Jun 28, 2013 05:19
Hello modding community,
I am pleased to announce the addition of the LuaVoxelManip to Minetest's Lua API. Ever since the beginning, modders have been looking for a way to manipulate nodes on the map in bulk. Just until recently with the addition of the Schematic API, this was not possible. However, now with VoxelManip, there is a fast, complete, and official way to accomplish this task. It may seem that this API is much more technical and less user friendly to use than others, but this is necessary in order to maximize speed - its central purpose.
Within on_generate callbacks, the same exact VoxelManip object used to generate the chunk being handled with the internal map generator can be obtained using the new minetest.get_mapgen_object API. Paired with the singlenode map generator, this is especially convenient for creating completely Lua-based mapgens.
For testing purposes, I made a very simple 3d noise-based map generator, which can also be used as a decent reference of how to use VoxelManip:
How well does it perform?
Setup:
CPU: Intel Xeon E3-1230v2
OS: FreeBSD/amd64 9.1-RELEASE
CC: g++ 4.2.2, -g, -O1
On average, to generate an 80x80x80 chunk of this, it takes:
minetest.env:set_node: 6854.4ms
VoxelManip: 153.5ms
Mapgen in core: 60ms (estimated)
So, generating map with VoxelManip in pure Lua is only about 2.5x slower than a mapgen in the core, but a whole 45x faster than using set_node for everything.
I strongly encourage everybody to use this interface and *not* the Schematic API for VoxelManip tasks. The primary purpose of the Schematic API is to define discrete, relatively static structures such as trees, spikes, huts, etc. so they can be randomly placed on the map at generation time. minetest.create_structure is to make a new structure. minetest.place_structure is not exactly a necessary API, but convenient for checking to see that the correct structure was created and did not take much additional effort at all to implement; an added bonus was that it could be used in the same way WorldEdit schematics were - this was not the intent however. Further, defining the schematic completely within Lua via the node table was again a feature added for flexibility, and because it did not take much effort to add.
VoxelManip is even faster than the Schematic API, adds vastly more flexibility, is not hackish, and allows reading the map as well, which is needed for many node placement tasks. There is really no reason not to use it.
Also:
Apparently, having no way to find the real name of a node was a long-standing problem in mods.
As luck would have it, two API that were added needed by VoxelManip, minetest.get_content_id() and minetest.get_name_from_content_id(), can be used to find the real name of a node alias as follows:
local c = minetest.get_content_id(alias_name)
local real_name = minetest.get_name_from_content_id(c)
Enjoy!
I am pleased to announce the addition of the LuaVoxelManip to Minetest's Lua API. Ever since the beginning, modders have been looking for a way to manipulate nodes on the map in bulk. Just until recently with the addition of the Schematic API, this was not possible. However, now with VoxelManip, there is a fast, complete, and official way to accomplish this task. It may seem that this API is much more technical and less user friendly to use than others, but this is necessary in order to maximize speed - its central purpose.
Within on_generate callbacks, the same exact VoxelManip object used to generate the chunk being handled with the internal map generator can be obtained using the new minetest.get_mapgen_object API. Paired with the singlenode map generator, this is especially convenient for creating completely Lua-based mapgens.
For testing purposes, I made a very simple 3d noise-based map generator, which can also be used as a decent reference of how to use VoxelManip:
How well does it perform?
Setup:
CPU: Intel Xeon E3-1230v2
OS: FreeBSD/amd64 9.1-RELEASE
CC: g++ 4.2.2, -g, -O1
On average, to generate an 80x80x80 chunk of this, it takes:
minetest.env:set_node: 6854.4ms
VoxelManip: 153.5ms
Mapgen in core: 60ms (estimated)
So, generating map with VoxelManip in pure Lua is only about 2.5x slower than a mapgen in the core, but a whole 45x faster than using set_node for everything.
I strongly encourage everybody to use this interface and *not* the Schematic API for VoxelManip tasks. The primary purpose of the Schematic API is to define discrete, relatively static structures such as trees, spikes, huts, etc. so they can be randomly placed on the map at generation time. minetest.create_structure is to make a new structure. minetest.place_structure is not exactly a necessary API, but convenient for checking to see that the correct structure was created and did not take much additional effort at all to implement; an added bonus was that it could be used in the same way WorldEdit schematics were - this was not the intent however. Further, defining the schematic completely within Lua via the node table was again a feature added for flexibility, and because it did not take much effort to add.
VoxelManip is even faster than the Schematic API, adds vastly more flexibility, is not hackish, and allows reading the map as well, which is needed for many node placement tasks. There is really no reason not to use it.
Also:
Apparently, having no way to find the real name of a node was a long-standing problem in mods.
As luck would have it, two API that were added needed by VoxelManip, minetest.get_content_id() and minetest.get_name_from_content_id(), can be used to find the real name of a node alias as follows:
local c = minetest.get_content_id(alias_name)
local real_name = minetest.get_name_from_content_id(c)
Enjoy!