2013-06-25 17:02:02 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "lua_api/l_vmanip.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "lua_api/l_internal.h"
|
2014-09-01 23:33:21 +02:00
|
|
|
#include "common/c_content.h"
|
2013-06-25 17:02:02 +02:00
|
|
|
#include "common/c_converter.h"
|
|
|
|
#include "emerge.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "environment.h"
|
|
|
|
#include "map.h"
|
2017-08-18 19:25:07 +02:00
|
|
|
#include "mapblock.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "server.h"
|
2017-11-08 23:56:20 +01:00
|
|
|
#include "mapgen/mapgen.h"
|
2016-12-10 19:02:44 +01:00
|
|
|
#include "voxelalgorithms.h"
|
2013-06-25 17:02:02 +02:00
|
|
|
|
|
|
|
// garbage collector
|
|
|
|
int LuaVoxelManip::gc_object(lua_State *L)
|
|
|
|
{
|
|
|
|
LuaVoxelManip *o = *(LuaVoxelManip **)(lua_touserdata(L, 1));
|
2014-07-30 03:39:24 +02:00
|
|
|
delete o;
|
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-28 03:12:44 +02:00
|
|
|
int LuaVoxelManip::l_read_from_map(lua_State *L)
|
2013-06-25 17:02:02 +02:00
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
MAP_LOCK_REQUIRED;
|
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 bp1 = getNodeBlockPos(check_v3s16(L, 2));
|
|
|
|
v3s16 bp2 = getNodeBlockPos(check_v3s16(L, 3));
|
2013-06-25 17:02:02 +02:00
|
|
|
sortBoxVerticies(bp1, bp2);
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
vm->initialEmerge(bp1, bp2);
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-28 03:12:44 +02:00
|
|
|
push_v3s16(L, vm->m_area.MinEdge);
|
|
|
|
push_v3s16(L, vm->m_area.MaxEdge);
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-28 03:12:44 +02:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaVoxelManip::l_get_data(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-05-17 06:07:45 +02:00
|
|
|
bool use_buffer = lua_istable(L, 2);
|
|
|
|
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2015-05-17 06:07:45 +02:00
|
|
|
u32 volume = vm->m_area.getVolume();
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2015-05-17 06:07:45 +02:00
|
|
|
if (use_buffer)
|
|
|
|
lua_pushvalue(L, 2);
|
|
|
|
else
|
2020-04-14 20:44:18 +02:00
|
|
|
lua_createtable(L, volume, 0);
|
2015-05-17 06:07:45 +02:00
|
|
|
|
|
|
|
for (u32 i = 0; i != volume; i++) {
|
2013-06-28 03:12:44 +02:00
|
|
|
lua_Integer cid = vm->m_data[i].getContent();
|
|
|
|
lua_pushinteger(L, cid);
|
2013-06-25 17:02:02 +02:00
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-28 03:12:44 +02:00
|
|
|
return 1;
|
2013-06-25 17:02:02 +02:00
|
|
|
}
|
|
|
|
|
2013-06-28 03:12:44 +02:00
|
|
|
int LuaVoxelManip::l_set_data(lua_State *L)
|
2013-06-25 17:02:02 +02:00
|
|
|
{
|
2013-06-28 03:12:44 +02:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
if (!lua_istable(L, 2))
|
2018-08-02 20:54:44 +02:00
|
|
|
throw LuaError("VoxelManip:set_data called with missing parameter");
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2015-05-17 06:07:45 +02:00
|
|
|
u32 volume = vm->m_area.getVolume();
|
|
|
|
for (u32 i = 0; i != volume; i++) {
|
2013-06-25 17:02:02 +02:00
|
|
|
lua_rawgeti(L, 2, i + 1);
|
2013-06-28 04:33:31 +02:00
|
|
|
content_t c = lua_tointeger(L, -1);
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
vm->m_data[i].setContent(c);
|
|
|
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-28 03:12:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaVoxelManip::l_write_to_map(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
MAP_LOCK_REQUIRED;
|
|
|
|
|
2013-06-28 03:12:44 +02:00
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2018-06-30 17:11:38 +02:00
|
|
|
bool update_light = !lua_isboolean(L, 2) || readParam<bool>(L, 2);
|
2016-12-10 19:02:44 +01:00
|
|
|
GET_ENV_PTR;
|
|
|
|
ServerMap *map = &(env->getServerMap());
|
2017-03-11 17:07:04 +01:00
|
|
|
if (o->is_mapgen_vm || !update_light) {
|
2016-12-10 19:02:44 +01:00
|
|
|
o->vm->blitBackAll(&(o->modified_blocks));
|
|
|
|
} else {
|
|
|
|
voxalgo::blit_back_with_light(map, o->vm,
|
|
|
|
&(o->modified_blocks));
|
|
|
|
}
|
2013-06-25 17:02:02 +02:00
|
|
|
|
2016-12-10 19:02:44 +01:00
|
|
|
MapEditEvent event;
|
|
|
|
event.type = MEET_OTHER;
|
2017-08-19 22:23:47 +02:00
|
|
|
for (const auto &modified_block : o->modified_blocks)
|
|
|
|
event.modified_blocks.insert(modified_block.first);
|
2013-06-28 03:12:44 +02:00
|
|
|
|
2019-09-24 19:05:28 +02:00
|
|
|
map->dispatchEvent(event);
|
2016-12-10 19:02:44 +01:00
|
|
|
|
|
|
|
o->modified_blocks.clear();
|
2014-07-30 03:39:24 +02:00
|
|
|
return 0;
|
2013-06-25 17:02:02 +02:00
|
|
|
}
|
|
|
|
|
2014-09-01 23:33:21 +02:00
|
|
|
int LuaVoxelManip::l_get_node_at(lua_State *L)
|
2013-06-25 17:02:02 +02:00
|
|
|
{
|
2014-09-01 23:33:21 +02:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
2015-10-25 05:45:18 +01:00
|
|
|
|
2018-02-10 21:04:16 +01:00
|
|
|
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
2014-09-01 23:33:21 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pos = check_v3s16(L, 2);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-10-25 05:45:18 +01:00
|
|
|
pushnode(L, o->vm->getNodeNoExNoEmerge(pos), ndef);
|
2014-09-01 23:33:21 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaVoxelManip::l_set_node_at(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
2015-10-25 05:45:18 +01:00
|
|
|
|
2018-02-10 21:04:16 +01:00
|
|
|
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
2014-09-01 23:33:21 +02:00
|
|
|
|
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pos = check_v3s16(L, 2);
|
2015-10-25 05:45:18 +01:00
|
|
|
MapNode n = readnode(L, 3, ndef);
|
2014-09-01 23:33:21 +02:00
|
|
|
|
|
|
|
o->vm->setNodeNoEmerge(pos, n);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaVoxelManip::l_update_liquids(lua_State *L)
|
|
|
|
{
|
|
|
|
GET_ENV_PTR;
|
|
|
|
|
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
|
|
|
Map *map = &(env->getMap());
|
2018-02-10 21:04:16 +01:00
|
|
|
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2013-06-25 17:02:02 +02:00
|
|
|
|
|
|
|
Mapgen mg;
|
|
|
|
mg.vm = vm;
|
|
|
|
mg.ndef = ndef;
|
|
|
|
|
|
|
|
mg.updateLiquid(&map->m_transforming_liquid,
|
|
|
|
vm->m_area.MinEdge, vm->m_area.MaxEdge);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaVoxelManip::l_calc_lighting(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2018-08-02 20:54:44 +02:00
|
|
|
if (!o->is_mapgen_vm) {
|
|
|
|
warningstream << "VoxelManip:calc_lighting called for a non-mapgen "
|
|
|
|
"VoxelManip object" << std::endl;
|
2013-06-30 04:22:25 +02:00
|
|
|
return 0;
|
2018-08-02 20:54:44 +02:00
|
|
|
}
|
2013-11-30 06:27:39 +01:00
|
|
|
|
2018-02-10 21:04:16 +01:00
|
|
|
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
2013-08-11 04:09:45 +02:00
|
|
|
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2013-06-30 04:22:25 +02:00
|
|
|
|
2015-01-05 07:18:53 +01:00
|
|
|
v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE;
|
|
|
|
v3s16 fpmin = vm->m_area.MinEdge;
|
|
|
|
v3s16 fpmax = vm->m_area.MaxEdge;
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pmin = lua_istable(L, 2) ? check_v3s16(L, 2) : fpmin + yblock;
|
|
|
|
v3s16 pmax = lua_istable(L, 3) ? check_v3s16(L, 3) : fpmax - yblock;
|
2018-06-30 17:11:38 +02:00
|
|
|
bool propagate_shadow = !lua_isboolean(L, 4) || readParam<bool>(L, 4);
|
2015-01-05 07:18:53 +01:00
|
|
|
|
|
|
|
sortBoxVerticies(pmin, pmax);
|
|
|
|
if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
|
2015-01-04 09:07:28 +01:00
|
|
|
throw LuaError("Specified voxel area out of VoxelManipulator bounds");
|
2013-11-30 06:27:39 +01:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
Mapgen mg;
|
|
|
|
mg.vm = vm;
|
|
|
|
mg.ndef = ndef;
|
2016-06-25 00:15:56 +02:00
|
|
|
mg.water_level = emerge->mgparams->water_level;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2015-12-02 04:28:03 +01:00
|
|
|
mg.calcLighting(pmin, pmax, fpmin, fpmax, propagate_shadow);
|
2013-06-25 17:02:02 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaVoxelManip::l_set_lighting(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2018-08-02 20:54:44 +02:00
|
|
|
if (!o->is_mapgen_vm) {
|
|
|
|
warningstream << "VoxelManip:set_lighting called for a non-mapgen "
|
|
|
|
"VoxelManip object" << std::endl;
|
2013-06-30 04:22:25 +02:00
|
|
|
return 0;
|
2018-08-02 20:54:44 +02:00
|
|
|
}
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-30 04:22:25 +02:00
|
|
|
if (!lua_istable(L, 2))
|
2018-08-02 20:54:44 +02:00
|
|
|
throw LuaError("VoxelManip:set_lighting called with missing parameter");
|
2013-06-25 17:02:02 +02:00
|
|
|
|
2013-06-30 04:22:25 +02:00
|
|
|
u8 light;
|
2013-11-21 06:45:17 +01:00
|
|
|
light = (getintfield_default(L, 2, "day", 0) & 0x0F);
|
2013-11-30 06:27:39 +01:00
|
|
|
light |= (getintfield_default(L, 2, "night", 0) & 0x0F) << 4;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2015-01-05 07:18:53 +01:00
|
|
|
v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE;
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pmin = lua_istable(L, 3) ? check_v3s16(L, 3) : vm->m_area.MinEdge + yblock;
|
|
|
|
v3s16 pmax = lua_istable(L, 4) ? check_v3s16(L, 4) : vm->m_area.MaxEdge - yblock;
|
2015-01-05 07:18:53 +01:00
|
|
|
|
|
|
|
sortBoxVerticies(pmin, pmax);
|
|
|
|
if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
|
2015-01-04 09:07:28 +01:00
|
|
|
throw LuaError("Specified voxel area out of VoxelManipulator bounds");
|
2013-11-30 06:27:39 +01:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
Mapgen mg;
|
|
|
|
mg.vm = vm;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2015-01-05 07:18:53 +01:00
|
|
|
mg.setLighting(light, pmin, pmax);
|
2013-06-25 17:02:02 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-30 03:16:08 +01:00
|
|
|
int LuaVoxelManip::l_get_light_data(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2013-11-30 03:16:08 +01:00
|
|
|
|
2015-05-17 06:07:45 +02:00
|
|
|
u32 volume = vm->m_area.getVolume();
|
2013-11-30 03:16:08 +01:00
|
|
|
|
2020-04-14 20:44:18 +02:00
|
|
|
lua_createtable(L, volume, 0);
|
2015-05-17 06:07:45 +02:00
|
|
|
for (u32 i = 0; i != volume; i++) {
|
2013-11-30 03:16:08 +01:00
|
|
|
lua_Integer light = vm->m_data[i].param1;
|
|
|
|
lua_pushinteger(L, light);
|
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaVoxelManip::l_set_light_data(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2013-11-30 03:16:08 +01:00
|
|
|
|
|
|
|
if (!lua_istable(L, 2))
|
2018-08-02 20:54:44 +02:00
|
|
|
throw LuaError("VoxelManip:set_light_data called with missing "
|
|
|
|
"parameter");
|
2013-11-30 03:16:08 +01:00
|
|
|
|
2015-05-17 06:07:45 +02:00
|
|
|
u32 volume = vm->m_area.getVolume();
|
|
|
|
for (u32 i = 0; i != volume; i++) {
|
2013-11-30 03:16:08 +01:00
|
|
|
lua_rawgeti(L, 2, i + 1);
|
|
|
|
u8 light = lua_tointeger(L, -1);
|
|
|
|
|
|
|
|
vm->m_data[i].param1 = light;
|
|
|
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-19 08:55:34 +01:00
|
|
|
int LuaVoxelManip::l_get_param2_data(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2016-10-29 16:22:18 +02:00
|
|
|
bool use_buffer = lua_istable(L, 2);
|
|
|
|
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2014-01-19 08:55:34 +01:00
|
|
|
|
2015-05-17 06:07:45 +02:00
|
|
|
u32 volume = vm->m_area.getVolume();
|
2014-01-19 08:55:34 +01:00
|
|
|
|
2016-10-29 16:22:18 +02:00
|
|
|
if (use_buffer)
|
|
|
|
lua_pushvalue(L, 2);
|
|
|
|
else
|
2020-04-14 20:44:18 +02:00
|
|
|
lua_createtable(L, volume, 0);
|
2016-10-29 16:22:18 +02:00
|
|
|
|
2015-05-17 06:07:45 +02:00
|
|
|
for (u32 i = 0; i != volume; i++) {
|
2014-01-19 08:55:34 +01:00
|
|
|
lua_Integer param2 = vm->m_data[i].param2;
|
|
|
|
lua_pushinteger(L, param2);
|
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaVoxelManip::l_set_param2_data(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2014-01-19 08:55:34 +01:00
|
|
|
|
|
|
|
if (!lua_istable(L, 2))
|
2018-08-02 20:54:44 +02:00
|
|
|
throw LuaError("VoxelManip:set_param2_data called with missing "
|
|
|
|
"parameter");
|
2014-01-19 08:55:34 +01:00
|
|
|
|
2015-05-17 06:07:45 +02:00
|
|
|
u32 volume = vm->m_area.getVolume();
|
|
|
|
for (u32 i = 0; i != volume; i++) {
|
2014-01-19 08:55:34 +01:00
|
|
|
lua_rawgeti(L, 2, i + 1);
|
|
|
|
u8 param2 = lua_tointeger(L, -1);
|
|
|
|
|
|
|
|
vm->m_data[i].param2 = param2;
|
|
|
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
int LuaVoxelManip::l_update_map(lua_State *L)
|
|
|
|
{
|
2014-07-30 03:39:24 +02:00
|
|
|
return 0;
|
2013-06-25 17:02:02 +02:00
|
|
|
}
|
|
|
|
|
2014-09-01 20:20:31 +02:00
|
|
|
int LuaVoxelManip::l_was_modified(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vm = o->vm;
|
2014-09-01 20:20:31 +02:00
|
|
|
|
|
|
|
lua_pushboolean(L, vm->m_is_dirty);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-28 05:09:36 +01:00
|
|
|
int LuaVoxelManip::l_get_emerged_area(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2014-12-28 05:09:36 +01:00
|
|
|
LuaVoxelManip *o = checkobject(L, 1);
|
|
|
|
|
|
|
|
push_v3s16(L, o->vm->m_area.MinEdge);
|
|
|
|
push_v3s16(L, o->vm->m_area.MaxEdge);
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2017-06-20 00:04:18 +02:00
|
|
|
LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) :
|
|
|
|
is_mapgen_vm(is_mg_vm),
|
|
|
|
vm(mmvm)
|
2013-06-26 23:19:39 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-19 23:54:58 +02:00
|
|
|
LuaVoxelManip::LuaVoxelManip(Map *map) : vm(new MMVManip(map))
|
2013-06-25 17:02:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-12-29 07:31:37 +01:00
|
|
|
LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2)
|
|
|
|
{
|
2017-06-19 23:54:58 +02:00
|
|
|
vm = new MMVManip(map);
|
2014-12-29 07:31:37 +01:00
|
|
|
|
|
|
|
v3s16 bp1 = getNodeBlockPos(p1);
|
|
|
|
v3s16 bp2 = getNodeBlockPos(p2);
|
|
|
|
sortBoxVerticies(bp1, bp2);
|
|
|
|
vm->initialEmerge(bp1, bp2);
|
|
|
|
}
|
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
LuaVoxelManip::~LuaVoxelManip()
|
|
|
|
{
|
2014-07-30 03:39:24 +02:00
|
|
|
if (!is_mapgen_vm)
|
|
|
|
delete vm;
|
2013-06-25 17:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// LuaVoxelManip()
|
|
|
|
// Creates an LuaVoxelManip and leaves it on top of stack
|
|
|
|
int LuaVoxelManip::create_object(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
GET_ENV_PTR;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-28 04:33:31 +02:00
|
|
|
Map *map = &(env->getMap());
|
2014-12-29 07:31:37 +01:00
|
|
|
LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ?
|
2015-04-17 07:03:13 +02:00
|
|
|
new LuaVoxelManip(map, check_v3s16(L, 1), check_v3s16(L, 2)) :
|
2014-12-29 07:31:37 +01:00
|
|
|
new LuaVoxelManip(map);
|
2014-12-28 05:09:36 +01:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
|
|
|
|
luaL_getmetatable(L, className);
|
|
|
|
lua_setmetatable(L, -2);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LuaVoxelManip *LuaVoxelManip::checkobject(lua_State *L, int narg)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
luaL_checktype(L, narg, LUA_TUSERDATA);
|
|
|
|
|
|
|
|
void *ud = luaL_checkudata(L, narg, className);
|
|
|
|
if (!ud)
|
|
|
|
luaL_typerror(L, narg, className);
|
2014-07-30 03:39:24 +02:00
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
return *(LuaVoxelManip **)ud; // unbox pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaVoxelManip::Register(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_newtable(L);
|
|
|
|
int methodtable = lua_gettop(L);
|
|
|
|
luaL_newmetatable(L, className);
|
|
|
|
int metatable = lua_gettop(L);
|
|
|
|
|
|
|
|
lua_pushliteral(L, "__metatable");
|
|
|
|
lua_pushvalue(L, methodtable);
|
|
|
|
lua_settable(L, metatable); // hide metatable from Lua getmetatable()
|
|
|
|
|
|
|
|
lua_pushliteral(L, "__index");
|
|
|
|
lua_pushvalue(L, methodtable);
|
|
|
|
lua_settable(L, metatable);
|
|
|
|
|
|
|
|
lua_pushliteral(L, "__gc");
|
|
|
|
lua_pushcfunction(L, gc_object);
|
|
|
|
lua_settable(L, metatable);
|
|
|
|
|
|
|
|
lua_pop(L, 1); // drop metatable
|
|
|
|
|
2021-05-25 20:20:16 +02:00
|
|
|
luaL_register(L, nullptr, methods); // fill methodtable
|
2013-06-25 17:02:02 +02:00
|
|
|
lua_pop(L, 1); // drop methodtable
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
// Can be created from Lua (VoxelManip())
|
2013-06-25 17:02:02 +02:00
|
|
|
lua_register(L, className, create_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char LuaVoxelManip::className[] = "VoxelManip";
|
2017-04-08 09:28:37 +02:00
|
|
|
const luaL_Reg LuaVoxelManip::methods[] = {
|
2013-06-28 03:12:44 +02:00
|
|
|
luamethod(LuaVoxelManip, read_from_map),
|
|
|
|
luamethod(LuaVoxelManip, get_data),
|
|
|
|
luamethod(LuaVoxelManip, set_data),
|
2014-09-01 23:33:21 +02:00
|
|
|
luamethod(LuaVoxelManip, get_node_at),
|
|
|
|
luamethod(LuaVoxelManip, set_node_at),
|
2013-06-28 03:12:44 +02:00
|
|
|
luamethod(LuaVoxelManip, write_to_map),
|
2013-06-25 17:02:02 +02:00
|
|
|
luamethod(LuaVoxelManip, update_map),
|
|
|
|
luamethod(LuaVoxelManip, update_liquids),
|
|
|
|
luamethod(LuaVoxelManip, calc_lighting),
|
|
|
|
luamethod(LuaVoxelManip, set_lighting),
|
2013-11-30 03:16:08 +01:00
|
|
|
luamethod(LuaVoxelManip, get_light_data),
|
|
|
|
luamethod(LuaVoxelManip, set_light_data),
|
2014-01-19 08:55:34 +01:00
|
|
|
luamethod(LuaVoxelManip, get_param2_data),
|
|
|
|
luamethod(LuaVoxelManip, set_param2_data),
|
2014-09-01 20:20:31 +02:00
|
|
|
luamethod(LuaVoxelManip, was_modified),
|
2014-12-28 05:09:36 +01:00
|
|
|
luamethod(LuaVoxelManip, get_emerged_area),
|
2013-06-25 17:02:02 +02:00
|
|
|
{0,0}
|
|
|
|
};
|