generated from your-land/yl_template
Implemennts adding and removing to lbm_list
This commit is contained in:
parent
681013c4ad
commit
0e40a09d60
@ -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
|
||||
}
|
||||
|
38
api.lua
38
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
|
||||
|
@ -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
|
||||
|
1
init.lua
1
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]")
|
||||
|
@ -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
|
||||
|
||||
|
29
lbm.lua
Normal file
29
lbm.lua
Normal file
@ -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:<whatever> 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)
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user