summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_vmanip.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-09-01 17:33:21 -0400
committerkwolekr <kwolekr@minetest.net>2014-09-01 17:33:21 -0400
commitf3eefeb7948b8b8d1a98f2f89baa39abc807f72d (patch)
tree86f51e45a4da09351b37a39610cd671e8dce0dfd /src/script/lua_api/l_vmanip.cpp
parent9e4e7072da8f565eef37da7558053a436b9cbba3 (diff)
downloadminetest-f3eefeb7948b8b8d1a98f2f89baa39abc807f72d.tar.gz
minetest-f3eefeb7948b8b8d1a98f2f89baa39abc807f72d.tar.bz2
minetest-f3eefeb7948b8b8d1a98f2f89baa39abc807f72d.zip
Add LuaVoxelManip methods: get_node_at() and set_node_at()
Diffstat (limited to 'src/script/lua_api/l_vmanip.cpp')
-rw-r--r--src/script/lua_api/l_vmanip.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp
index 2a3cfcafa..554a57343 100644
--- a/src/script/lua_api/l_vmanip.cpp
+++ b/src/script/lua_api/l_vmanip.cpp
@@ -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_internal.h"
+#include "common/c_content.h"
#include "common/c_converter.h"
#include "emerge.h"
#include "environment.h"
@@ -27,6 +28,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "mapgen.h"
+#define GET_ENV_PTR ServerEnvironment* env = \
+ dynamic_cast<ServerEnvironment*>(getEnv(L)); \
+ if (env == NULL) return 0
+
// garbage collector
int LuaVoxelManip::gc_object(lua_State *L)
{
@@ -105,13 +110,37 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
return 0;
}
-int LuaVoxelManip::l_update_liquids(lua_State *L)
+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);
- Environment *env = getEnv(L);
- if (!env)
- return 0;
+ 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)
+{
+ GET_ENV_PTR;
+
+ LuaVoxelManip *o = checkobject(L, 1);
Map *map = &(env->getMap());
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
@@ -399,6 +428,8 @@ const luaL_reg LuaVoxelManip::methods[] = {
luamethod(LuaVoxelManip, read_from_map),
luamethod(LuaVoxelManip, get_data),
luamethod(LuaVoxelManip, set_data),
+ luamethod(LuaVoxelManip, get_node_at),
+ luamethod(LuaVoxelManip, set_node_at),
luamethod(LuaVoxelManip, write_to_map),
luamethod(LuaVoxelManip, update_map),
luamethod(LuaVoxelManip, update_liquids),