]> git.lizzy.rs Git - minetest.git/blobdiff - src/script/cpp_api/s_env.cpp
Add callback on_mapblocks_changed
[minetest.git] / src / script / cpp_api / s_env.cpp
index 55c0a84f5b5ec1b50c613bc5d3988d1e45b07654..3cbb13cd2235e7a09602a6bc2254d79dfd8bcedf 100644 (file)
@@ -257,6 +257,18 @@ void ScriptApiEnv::on_emerge_area_completion(
        }
 }
 
+void ScriptApiEnv::check_for_falling(v3s16 p)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       int error_handler = PUSH_ERROR_HANDLER(L);
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "check_for_falling");
+       luaL_checktype(L, -1, LUA_TFUNCTION);
+       push_v3s16(L, p);
+       PCALL_RES(lua_pcall(L, 1, 0, error_handler));
+}
+
 void ScriptApiEnv::on_liquid_transformed(
        const std::vector<std::pair<v3s16, MapNode>> &list)
 {
@@ -287,3 +299,36 @@ void ScriptApiEnv::on_liquid_transformed(
 
        runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
 }
+
+void ScriptApiEnv::on_mapblocks_changed(const std::unordered_set<v3s16> &set)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.registered_on_mapblocks_changed
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_mapblocks_changed");
+       luaL_checktype(L, -1, LUA_TTABLE);
+       lua_remove(L, -2);
+
+       // Convert the set to a set of position hashes
+       lua_createtable(L, 0, set.size());
+       for(const v3s16 &p : set) {
+               lua_pushnumber(L, hash_node_position(p));
+               lua_pushboolean(L, true);
+               lua_rawset(L, -3);
+       }
+       lua_pushinteger(L, set.size());
+
+       runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
+}
+
+bool ScriptApiEnv::has_on_mapblocks_changed()
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.registered_on_mapblocks_changed
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_mapblocks_changed");
+       luaL_checktype(L, -1, LUA_TTABLE);
+       return lua_objlen(L, -1) > 0;
+}