mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add callback on_mapblocks_changed
This commit is contained in:
parent
7701e70dc9
commit
5c248c2d7d
10 changed files with 141 additions and 6 deletions
|
@ -299,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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue