diff options
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_env.cpp | 11 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.cpp | 22 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.h | 4 |
3 files changed, 19 insertions, 18 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 9e713b9b8..c8c1ca0e1 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -636,14 +636,9 @@ int ModApiEnvMod::l_get_voxel_manip(lua_State *L) GET_ENV_PTR; Map *map = &(env->getMap()); - LuaVoxelManip *o = new LuaVoxelManip(map); - - if (lua_istable(L, 1) && lua_istable(L, 2)) { - v3s16 p1 = getNodeBlockPos(read_v3s16(L, 1)); - v3s16 p2 = getNodeBlockPos(read_v3s16(L, 2)); - sortBoxVerticies(p1, p2); - o->vm->initializeBlank(p1, p2); - } + LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? + new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) : + new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, "VoxelManip"); diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index fb52aa21a..6c12baf92 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -367,6 +367,17 @@ LuaVoxelManip::LuaVoxelManip(Map *map) this->is_mapgen_vm = false; } +LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2) +{ + this->vm = new ManualMapVoxelManipulator(map); + this->is_mapgen_vm = false; + + v3s16 bp1 = getNodeBlockPos(p1); + v3s16 bp2 = getNodeBlockPos(p2); + sortBoxVerticies(bp1, bp2); + vm->initialEmerge(bp1, bp2); +} + LuaVoxelManip::~LuaVoxelManip() { if (!is_mapgen_vm) @@ -384,14 +395,9 @@ int LuaVoxelManip::create_object(lua_State *L) return 0; Map *map = &(env->getMap()); - LuaVoxelManip *o = new LuaVoxelManip(map); - - if (lua_istable(L, 1) && lua_istable(L, 2)) { - v3s16 p1 = getNodeBlockPos(read_v3s16(L, 1)); - v3s16 p2 = getNodeBlockPos(read_v3s16(L, 2)); - sortBoxVerticies(p1, p2); - o->vm->initializeBlank(p1, p2); - } + LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? + new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) : + new LuaVoxelManip(map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, className); diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index ead6efbc4..887b18663 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -33,6 +33,7 @@ class ManualMapVoxelManipulator; */ class LuaVoxelManip : public ModApiBase { private: + ManualMapVoxelManipulator *vm; std::map<v3s16, MapBlock *> modified_blocks; bool is_mapgen_vm; @@ -64,9 +65,8 @@ private: static int l_get_emerged_area(lua_State *L); public: - ManualMapVoxelManipulator *vm; - LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm); + LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2); LuaVoxelManip(Map *map); ~LuaVoxelManip(); |