diff options
author | Dániel Juhász <juhdanad@gmail.com> | 2017-03-11 17:07:04 +0100 |
---|---|---|
committer | Ekdohibs <nathanael.courant@laposte.net> | 2017-04-20 05:39:14 +0200 |
commit | 57e5aa662851485902575c3c747437e365bf72c8 (patch) | |
tree | 3e8469a85db5577140110e5d87a98514f5dd8d2f /src/script/lua_api | |
parent | 6d1e6f889826a5802e17f53f99000a51b2e00066 (diff) | |
download | minetest-57e5aa662851485902575c3c747437e365bf72c8.tar.gz minetest-57e5aa662851485902575c3c747437e365bf72c8.tar.bz2 minetest-57e5aa662851485902575c3c747437e365bf72c8.zip |
Light update for map blocks
This is not really different from the light update of a voxel
manipulator. This update does not assume that the lighting was correct
before, therefore it is useful for correction.
Also expose this function to the Lua API for light correction, and
allow voxel manipulators not to update the light.
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_env.cpp | 31 | ||||
-rw-r--r-- | src/script/lua_api/l_env.h | 3 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.cpp | 3 |
3 files changed, 36 insertions, 1 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 4fad7b37c..1fa7845b5 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -847,6 +847,36 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L) return 1; } +// fix_light(p1, p2) +int ModApiEnvMod::l_fix_light(lua_State *L) +{ + GET_ENV_PTR; + + v3s16 blockpos1 = getContainerPos(read_v3s16(L, 1), MAP_BLOCKSIZE); + v3s16 blockpos2 = getContainerPos(read_v3s16(L, 2), MAP_BLOCKSIZE); + ServerMap &map = env->getServerMap(); + std::map<v3s16, MapBlock *> modified_blocks; + bool success = true; + v3s16 blockpos; + for (blockpos.X = blockpos1.X; blockpos.X <= blockpos2.X; blockpos.X++) + for (blockpos.Y = blockpos1.Y; blockpos.Y <= blockpos2.Y; blockpos.Y++) + for (blockpos.Z = blockpos1.Z; blockpos.Z <= blockpos2.Z; blockpos.Z++) { + success = success & map.repairBlockLight(blockpos, &modified_blocks); + } + if (modified_blocks.size() > 0) { + MapEditEvent event; + event.type = MEET_OTHER; + for (std::map<v3s16, MapBlock *>::iterator it = modified_blocks.begin(); + it != modified_blocks.end(); ++it) + event.modified_blocks.insert(it->first); + + map.dispatchEvent(&event); + } + lua_pushboolean(L, success); + + return 1; +} + // emerge_area(p1, p2, [callback, context]) // emerge mapblocks in area p1..p2, calls callback with context upon completion int ModApiEnvMod::l_emerge_area(lua_State *L) @@ -1089,6 +1119,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top) API_FCT(find_node_near); API_FCT(find_nodes_in_area); API_FCT(find_nodes_in_area_under_air); + API_FCT(fix_light); API_FCT(emerge_area); API_FCT(delete_area); API_FCT(get_perlin); diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index 38b2282d7..3f688b398 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -128,6 +128,9 @@ private: // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" static int l_find_nodes_in_area_under_air(lua_State *L); + // fix_light(p1, p2) -> true/false + static int l_fix_light(lua_State *L); + // emerge_area(p1, p2) static int l_emerge_area(lua_State *L); diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index 7316fb200..254a7e5a6 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -110,9 +110,10 @@ int LuaVoxelManip::l_write_to_map(lua_State *L) MAP_LOCK_REQUIRED; LuaVoxelManip *o = checkobject(L, 1); + bool update_light = lua_isboolean(L, 2) ? lua_toboolean(L, 2) : true; GET_ENV_PTR; ServerMap *map = &(env->getServerMap()); - if (o->is_mapgen_vm) { + if (o->is_mapgen_vm || !update_light) { o->vm->blitBackAll(&(o->modified_blocks)); } else { voxalgo::blit_back_with_light(map, o->vm, |