]> git.lizzy.rs Git - minetest.git/commitdiff
Expose dtime_s to LBM handler
authorsfan5 <sfan5@live.de>
Sun, 4 Dec 2022 11:35:14 +0000 (12:35 +0100)
committerGitHub <noreply@github.com>
Sun, 4 Dec 2022 11:35:14 +0000 (12:35 +0100)
doc/lua_api.txt
src/script/lua_api/l_env.cpp
src/script/lua_api/l_env.h
src/serverenvironment.cpp
src/serverenvironment.h

index e8e32c53607e1c90d626ea1efb33608357fa4c6c..e017df88069064a3360939abdc28afddc505c052 100644 (file)
@@ -7972,8 +7972,10 @@ gets activated (not loaded!)
         -- and not only the first time the block gets activated after the LBM
         -- was introduced.
 
-        action = function(pos, node),
+        action = function(pos, node, dtime_s),
         -- Function triggered for each qualifying node.
+        -- `dtime_s` is the in-game time (in seconds) elapsed since the block
+        -- was last active
     }
 
 Tile definition
index 6421011661266b8d5d73ea4f1e38d173889cbe66..45d444d55d61ceb2bb322b75082cd3deaa9b9a23 100644 (file)
@@ -109,7 +109,8 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
        lua_pop(L, 1); // Pop error handler
 }
 
-void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n)
+void LuaLBM::trigger(ServerEnvironment *env, v3s16 p,
+       const MapNode n, const float dtime_s)
 {
        ServerScripting *scriptIface = env->getScriptIface();
        scriptIface->realityCheck();
@@ -141,8 +142,9 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n)
        lua_remove(L, -2); // Remove registered_lbms[m_id]
        push_v3s16(L, p);
        pushnode(L, n);
+       lua_pushnumber(L, dtime_s);
 
-       int result = lua_pcall(L, 2, 0, error_handler);
+       int result = lua_pcall(L, 3, 0, error_handler);
        if (result)
                scriptIface->scriptError(result, "LuaLBM::trigger");
 
index 3b386f86a37d367d9357974bdec6ebf06e3771c9..08782a4fbbd6c820bba5e619fd4a2d267640e422 100644 (file)
@@ -287,7 +287,7 @@ class LuaLBM : public LoadingBlockModifierDef
                this->trigger_contents = trigger_contents;
                this->name = name;
        }
-       virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n);
+       virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n, float dtime_s);
 };
 
 //! Lua wrapper for RaycastState objects
index 045f0599419d15384d3cf3327348e4552f3b4d92..9dd5ba621f565bd13b0126c7b2880ec1c66fe961 100644 (file)
@@ -249,7 +249,8 @@ std::string LBMManager::createIntroductionTimesString()
        return oss.str();
 }
 
-void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp)
+void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block,
+               const u32 stamp, const float dtime_s)
 {
        // Precondition, we need m_lbm_lookup to be initialized
        FATAL_ERROR_IF(!m_query_mode,
@@ -280,7 +281,7 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp)
                                        if (!lbm_list)
                                                continue;
                                        for (auto lbmdef : *lbm_list) {
-                                               lbmdef->trigger(env, pos + pos_of_block, n);
+                                               lbmdef->trigger(env, pos + pos_of_block, n, dtime_s);
                                        }
                                }
        }
@@ -997,7 +998,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
        activateObjects(block, dtime_s);
 
        /* Handle LoadingBlockModifiers */
-       m_lbm_mgr.applyLBMs(this, block, stamp);
+       m_lbm_mgr.applyLBMs(this, block, stamp, (float)dtime_s);
 
        // Run node timers
        block->step((float)dtime_s, [&](v3s16 p, MapNode n, f32 d) -> bool {
index 4eb7ab22ae2eb96c2c572f23521403d548b1bbb7..5c4b23f402d6a5e26e36d35f14dcc45fba4eade8 100644 (file)
@@ -95,7 +95,8 @@ struct LoadingBlockModifierDef
 
        virtual ~LoadingBlockModifierDef() = default;
 
-       virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){};
+       virtual void trigger(ServerEnvironment *env, v3s16 p,
+                       MapNode n, float dtime_s) {};
 };
 
 struct LBMContentMapping
@@ -129,7 +130,8 @@ class LBMManager
        std::string createIntroductionTimesString();
 
        // Don't call this before loadIntroductionTimes() ran.
-       void applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp);
+       void applyLBMs(ServerEnvironment *env, MapBlock *block,
+                       u32 stamp, float dtime_s);
 
        // Warning: do not make this std::unordered_map, order is relevant here
        typedef std::map<u32, LBMContentMapping> lbm_lookup_map;