diff --git a/README.md b/README.md index a1a1cb5..5047e36 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ yl_api_nodestages.debug = false ``` Set to true to enable debug mode +``` +yl_api_nodestages.run_lbm = true +``` + +Set to true to enable the timer restart lbm, set to false to disable it + ## Usage This mod can be used in singleplayer and multiplayer. It comes with no direct content but exposes functions you can use in your mod. @@ -53,7 +59,8 @@ local stage = { drawtype = "normal", ... }, - overwrite = true, -- optional, boolean, false breaks during registration if the node has on_timer or on_construct. true overwrites regardless + overwrite = false, -- optional, boolean, false breaks during registration if the node has on_timer or on_construct. true overwrites regardless + restart = true, -- optional, boolean, true restarts the nodetimer via lbm, false does not _previous = {}, -- DO NOT USE, this holds the history to be accessed by delete_stage only _version = 1, -- DO NOT USE, this holds the version of the datastructure, will increase when datastructure changes } diff --git a/api.lua b/api.lua index 74a73fd..3d234cf 100644 --- a/api.lua +++ b/api.lua @@ -116,6 +116,19 @@ local function add_stage(p_stage) end end + -- Add to lbm_nodenames + if ((stage.restart == false) or (stage.restart == nil)) then + --[[ TODO: Make add and delete into a function: + for i=#yl_api_nodestages.lbm_nodenames,1,-1 do + if (yl_api_nodestages.lbm_nodenames[i] == modname .. ":" .. nodename) then + table.remove(yl_api_nodestages.lbm_nodenames, i) + break + end + end + table.insert(yl_api_nodestages.lbm_nodenames, stage.stage_name) + ]]-- + end + target_def._stage = stage target_def.on_timer = yl_api_nodestages.on_timer target_def.on_construct = yl_api_nodestages.on_construct @@ -195,6 +208,11 @@ local function overwrite_stage(p_stage) end end + -- Add to lbm_nodenames + if ((stage.restart == false) or (stage.restart == nil)) then + table.insert(yl_api_nodestages.lbm_nodenames, stage.stage_name) + end + -- Assign the new values target_def._stage = stage @@ -256,6 +274,18 @@ local function rollback_stage(modname, nodename) return false, yl_api_nodestages.t("previous_stage_not_table") end + -- Remove current from lbm_names + for i=#yl_api_nodestages.lbm_nodenames,1,-1 do + if (yl_api_nodestages.lbm_nodenames[i] == modname .. ":" .. nodename) then + table.remove(yl_api_nodestages.lbm_nodenames, i) + break + end + end + -- Add to lbm_nodenames + if ((previous.stage.restart == false) or (previous.stage.restart == nil)) then + table.insert(yl_api_nodestages.lbm_nodenames, previous.stage.stage_name) + end + def._stage = previous.stage def.on_timer = previous.on_timer def.on_construct = previous.on_construct @@ -296,6 +326,14 @@ local function delete_stage(modname, nodename) return false, yl_api_nodestages.t("stage_not_table") end + -- Remove current from lbm_names + for i=#yl_api_nodestages.lbm_nodenames,1,-1 do + if (yl_api_nodestages.lbm_nodenames[i] == modname .. ":" .. nodename) then + table.remove(yl_api_nodestages.lbm_nodenames, i) + break + end + end + def._stage = nil def.on_timer = nil def.on_construct = nil diff --git a/config.lua b/config.lua index 17f7155..3e9ad22 100644 --- a/config.lua +++ b/config.lua @@ -4,3 +4,5 @@ yl_api_nodestages.settings = {} yl_api_nodestages.settings.debug = minetest.settings:get("yl_api_nodestages.debug") or true + +yl_api_nodestages.settings.run_lbm = minetest.settings:get("yl_api_nodestages.run_lbm") or true diff --git a/init.lua b/init.lua index ae3f389..8eab65d 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,7 @@ dofile(yl_api_nodestages.modpath .. "config.lua") dofile(yl_api_nodestages.modpath .. "internal.lua") dofile(yl_api_nodestages.modpath .. "api.lua") dofile(yl_api_nodestages.modpath .. "initialize.lua") +dofile(yl_api_nodestages.modpath .. "lbm.lua") local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000 minetest.log("action", "[MOD] yl_api_nodestages loaded in [" .. mod_end_time .. "s]") diff --git a/initialize.lua b/initialize.lua index 55ac9f4..616e0cc 100644 --- a/initialize.lua +++ b/initialize.lua @@ -1,4 +1,5 @@ local function run_each_serverstart() + yl_api_nodestages.lbm_nodenames = {} minetest.after(0.0, yl_api_nodestages.validate_all_stages) end diff --git a/lbm.lua b/lbm.lua new file mode 100644 index 0000000..8da04b3 --- /dev/null +++ b/lbm.lua @@ -0,0 +1,29 @@ +local function action(pos, node, dtime_s) + +end + +local def = { + label = "Nodetimer Restart", + -- Descriptive label for profiling purposes (optional). + -- Definitions with identical labels will be listed as one. + + name = "yl_api_nodestages:nodetimer_restart", + -- Identifier of the LBM, should follow the modname: convention + + nodenames = yl_api_nodestages.lbm_nodenames, + -- List of node names to trigger the LBM on. + -- Names of non-registered nodes and groups (as group:groupname) + -- will work as well. + + run_at_every_load = true, + -- Whether to run the LBM's action every time a block gets activated, + -- and not only the first time the block gets activated after the LBM + -- was introduced. + + action = action, + -- Function triggered for each qualifying node. + -- `dtime_s` is the in-game time (in seconds) elapsed since the block + -- was last active +} + +minetest.register_lbm(def) diff --git a/settingtypes.txt b/settingtypes.txt index 941ef8e..ded8d05 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -4,3 +4,8 @@ # Set this to true to enable debug mode, it will output some more values to log # Optional, default is false yl_api_nodestages.debug (Debug mode) bool false + +# Run Nodetimer Restart LBM +Set to true to enable the timer restart lbm, set to false to disable it +# Optional, default is true +yl_api_nodestages.run_lbm (Run Nodetimer Restart LBM) bool true