Skip to content

Commit f3eefeb

Browse files
committedSep 1, 2014
Add LuaVoxelManip methods: get_node_at() and set_node_at()
1 parent 9e4e707 commit f3eefeb

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed
 

‎doc/lua_api.txt

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

‎src/script/lua_api/l_env.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3535
#include "treegen.h"
3636
#include "pathfinder.h"
3737

38-
3938
#define GET_ENV_PTR ServerEnvironment* env = \
4039
dynamic_cast<ServerEnvironment*>(getEnv(L)); \
41-
if( env == NULL) return 0
40+
if (env == NULL) return 0
4241

4342
///////////////////////////////////////////////////////////////////////////////
4443

‎src/script/lua_api/l_vmanip.cpp

+35-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2020

2121
#include "lua_api/l_vmanip.h"
2222
#include "lua_api/l_internal.h"
23+
#include "common/c_content.h"
2324
#include "common/c_converter.h"
2425
#include "emerge.h"
2526
#include "environment.h"
2627
#include "map.h"
2728
#include "server.h"
2829
#include "mapgen.h"
2930

31+
#define GET_ENV_PTR ServerEnvironment* env = \
32+
dynamic_cast<ServerEnvironment*>(getEnv(L)); \
33+
if (env == NULL) return 0
34+
3035
// garbage collector
3136
int LuaVoxelManip::gc_object(lua_State *L)
3237
{
@@ -105,13 +110,37 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
105110
return 0;
106111
}
107112

108-
int LuaVoxelManip::l_update_liquids(lua_State *L)
113+
int LuaVoxelManip::l_get_node_at(lua_State *L)
109114
{
115+
NO_MAP_LOCK_REQUIRED;
116+
GET_ENV_PTR;
117+
110118
LuaVoxelManip *o = checkobject(L, 1);
119+
v3s16 pos = read_v3s16(L, 2);
111120

112-
Environment *env = getEnv(L);
113-
if (!env)
114-
return 0;
121+
pushnode(L, o->vm->getNodeNoExNoEmerge(pos), env->getGameDef()->ndef());
122+
return 1;
123+
}
124+
125+
int LuaVoxelManip::l_set_node_at(lua_State *L)
126+
{
127+
NO_MAP_LOCK_REQUIRED;
128+
GET_ENV_PTR;
129+
130+
LuaVoxelManip *o = checkobject(L, 1);
131+
v3s16 pos = read_v3s16(L, 2);
132+
MapNode n = readnode(L, 3, env->getGameDef()->ndef());
133+
134+
o->vm->setNodeNoEmerge(pos, n);
135+
136+
return 0;
137+
}
138+
139+
int LuaVoxelManip::l_update_liquids(lua_State *L)
140+
{
141+
GET_ENV_PTR;
142+
143+
LuaVoxelManip *o = checkobject(L, 1);
115144

116145
Map *map = &(env->getMap());
117146
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
@@ -399,6 +428,8 @@ const luaL_reg LuaVoxelManip::methods[] = {
399428
luamethod(LuaVoxelManip, read_from_map),
400429
luamethod(LuaVoxelManip, get_data),
401430
luamethod(LuaVoxelManip, set_data),
431+
luamethod(LuaVoxelManip, get_node_at),
432+
luamethod(LuaVoxelManip, set_node_at),
402433
luamethod(LuaVoxelManip, write_to_map),
403434
luamethod(LuaVoxelManip, update_map),
404435
luamethod(LuaVoxelManip, update_liquids),

‎src/script/lua_api/l_vmanip.h

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class LuaVoxelManip : public ModApiBase {
4747
static int l_set_data(lua_State *L);
4848
static int l_write_to_map(lua_State *L);
4949

50+
static int l_get_node_at(lua_State *L);
51+
static int l_set_node_at(lua_State *L);
52+
5053
static int l_update_map(lua_State *L);
5154
static int l_update_liquids(lua_State *L);
5255

0 commit comments

Comments
 (0)
Please sign in to comment.