Add LuaVoxelManip methods: get_node_at() and set_node_at()

This commit is contained in:
kwolekr 2014-09-01 17:33:21 -04:00
parent 9e4e7072da
commit f3eefeb794
4 changed files with 41 additions and 6 deletions

@ -2077,6 +2077,8 @@ methods:
^ returns actual emerged pmin, actual emerged pmax ^ returns actual emerged pmin, actual emerged pmax
- write_to_map(): Writes the data loaded from the VoxelManip back to the map. - write_to_map(): Writes the data loaded from the VoxelManip back to the map.
^ important: data must be set using VoxelManip:set_data before calling this ^ important: data must be set using VoxelManip:set_data before calling this
- get_node_at(pos): Returns a MapNode table of the node currently loaded in the VoxelManip at that position
- set_node_at(pos, node): Sets a specific MapNode in the VoxelManip at that position
- get_data(): Gets the data read into the VoxelManip object - get_data(): Gets the data read into the VoxelManip object
^ returns raw node data is in the form of an array of node content ids ^ returns raw node data is in the form of an array of node content ids
- set_data(data): Sets the data contents of the VoxelManip object - set_data(data): Sets the data contents of the VoxelManip object

@ -35,10 +35,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "treegen.h" #include "treegen.h"
#include "pathfinder.h" #include "pathfinder.h"
#define GET_ENV_PTR ServerEnvironment* env = \ #define GET_ENV_PTR ServerEnvironment* env = \
dynamic_cast<ServerEnvironment*>(getEnv(L)); \ dynamic_cast<ServerEnvironment*>(getEnv(L)); \
if( env == NULL) return 0 if (env == NULL) return 0
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_vmanip.h" #include "lua_api/l_vmanip.h"
#include "lua_api/l_internal.h" #include "lua_api/l_internal.h"
#include "common/c_content.h"
#include "common/c_converter.h" #include "common/c_converter.h"
#include "emerge.h" #include "emerge.h"
#include "environment.h" #include "environment.h"
@ -27,6 +28,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h" #include "server.h"
#include "mapgen.h" #include "mapgen.h"
#define GET_ENV_PTR ServerEnvironment* env = \
dynamic_cast<ServerEnvironment*>(getEnv(L)); \
if (env == NULL) return 0
// garbage collector // garbage collector
int LuaVoxelManip::gc_object(lua_State *L) int LuaVoxelManip::gc_object(lua_State *L)
{ {
@ -105,13 +110,37 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
return 0; return 0;
} }
int LuaVoxelManip::l_get_node_at(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
GET_ENV_PTR;
LuaVoxelManip *o = checkobject(L, 1);
v3s16 pos = read_v3s16(L, 2);
pushnode(L, o->vm->getNodeNoExNoEmerge(pos), env->getGameDef()->ndef());
return 1;
}
int LuaVoxelManip::l_set_node_at(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
GET_ENV_PTR;
LuaVoxelManip *o = checkobject(L, 1);
v3s16 pos = read_v3s16(L, 2);
MapNode n = readnode(L, 3, env->getGameDef()->ndef());
o->vm->setNodeNoEmerge(pos, n);
return 0;
}
int LuaVoxelManip::l_update_liquids(lua_State *L) int LuaVoxelManip::l_update_liquids(lua_State *L)
{ {
LuaVoxelManip *o = checkobject(L, 1); GET_ENV_PTR;
Environment *env = getEnv(L); LuaVoxelManip *o = checkobject(L, 1);
if (!env)
return 0;
Map *map = &(env->getMap()); Map *map = &(env->getMap());
INodeDefManager *ndef = getServer(L)->getNodeDefManager(); INodeDefManager *ndef = getServer(L)->getNodeDefManager();
@ -399,6 +428,8 @@ const luaL_reg LuaVoxelManip::methods[] = {
luamethod(LuaVoxelManip, read_from_map), luamethod(LuaVoxelManip, read_from_map),
luamethod(LuaVoxelManip, get_data), luamethod(LuaVoxelManip, get_data),
luamethod(LuaVoxelManip, set_data), luamethod(LuaVoxelManip, set_data),
luamethod(LuaVoxelManip, get_node_at),
luamethod(LuaVoxelManip, set_node_at),
luamethod(LuaVoxelManip, write_to_map), luamethod(LuaVoxelManip, write_to_map),
luamethod(LuaVoxelManip, update_map), luamethod(LuaVoxelManip, update_map),
luamethod(LuaVoxelManip, update_liquids), luamethod(LuaVoxelManip, update_liquids),

@ -47,6 +47,9 @@ private:
static int l_set_data(lua_State *L); static int l_set_data(lua_State *L);
static int l_write_to_map(lua_State *L); static int l_write_to_map(lua_State *L);
static int l_get_node_at(lua_State *L);
static int l_set_node_at(lua_State *L);
static int l_update_map(lua_State *L); static int l_update_map(lua_State *L);
static int l_update_liquids(lua_State *L); static int l_update_liquids(lua_State *L);