@@ -20,13 +20,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
20
20
21
21
#include " lua_api/l_vmanip.h"
22
22
#include " lua_api/l_internal.h"
23
+ #include " common/c_content.h"
23
24
#include " common/c_converter.h"
24
25
#include " emerge.h"
25
26
#include " environment.h"
26
27
#include " map.h"
27
28
#include " server.h"
28
29
#include " mapgen.h"
29
30
31
+ #define GET_ENV_PTR ServerEnvironment* env = \
32
+ dynamic_cast <ServerEnvironment*>(getEnv(L)); \
33
+ if (env == NULL ) return 0
34
+
30
35
// garbage collector
31
36
int LuaVoxelManip::gc_object (lua_State *L)
32
37
{
@@ -105,13 +110,37 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
105
110
return 0 ;
106
111
}
107
112
108
- int LuaVoxelManip::l_update_liquids (lua_State *L)
113
+ int LuaVoxelManip::l_get_node_at (lua_State *L)
109
114
{
115
+ NO_MAP_LOCK_REQUIRED;
116
+ GET_ENV_PTR;
117
+
110
118
LuaVoxelManip *o = checkobject (L, 1 );
119
+ v3s16 pos = read_v3s16 (L, 2 );
111
120
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 );
115
144
116
145
Map *map = &(env->getMap ());
117
146
INodeDefManager *ndef = getServer (L)->getNodeDefManager ();
@@ -399,6 +428,8 @@ const luaL_reg LuaVoxelManip::methods[] = {
399
428
luamethod (LuaVoxelManip, read_from_map),
400
429
luamethod (LuaVoxelManip, get_data),
401
430
luamethod (LuaVoxelManip, set_data),
431
+ luamethod (LuaVoxelManip, get_node_at),
432
+ luamethod (LuaVoxelManip, set_node_at),
402
433
luamethod (LuaVoxelManip, write_to_map),
403
434
luamethod (LuaVoxelManip, update_map),
404
435
luamethod (LuaVoxelManip, update_liquids),
0 commit comments