Implements add_stage

This commit is contained in:
AliasAlreadyTaken 2024-07-04 14:43:42 +02:00
parent fa99068a60
commit f4fed644e1
3 changed files with 44 additions and 3 deletions

View File

@ -58,7 +58,7 @@ local stage = {
drawtype = "normal",
...
},
overwrite = true
overwrite = true -- optional, boolean, false breaks during registration if the node has on_timer or on_construct. true overwrites regardless
}
}
```

25
api.lua
View File

@ -41,13 +41,14 @@ end
local function create_stagenode(stage)
local success, stage = yl_api_nodestages.get_copy_of_valid_stage(stage)
local success, stage = yl_api_nodestages.get_valid_copy_of_stage(stage)
if success == false then
return false, stage
end
-- MT properties
local nodename = stage.stage_name
local node_definition = stage.node_definition
node_definition.description = stage.description
node_definition.tiles = stage.tiles
@ -70,15 +71,35 @@ end
local function add_stage(stage)
local success, stage = yl_api_nodestages.get_copy_of_valid_stage(stage)
local success, stage = yl_api_nodestages.get_valid_copy_of_stage(stage)
if success == false then
return false, stage
end
local nodename = stage.stage_name
local node_definition = stage.node_definition
local target_def = minetest.registered_nodes[nodename]
if (target_def == nil) then
return false, yl_api_nodestages.t("error_item_not_exists", dump(nodename))
end
if (target_def.on_timer ~= nil) then
return false, yl_api_nodestages.t("error_item_has_timer", dump(nodename))
end
if (target_def.on_construct ~= nil) then
return false, yl_api_nodestages.t("error_item_has_construct", dump(nodename))
end
target_def._stage = stage
if (minetest.registered_nodes[nodename]._stage == nil) then
return false, t("stage_not_created")
end
return true
end
function yl_api_nodestages.add_stage(stage)

View File

@ -33,6 +33,26 @@ local stage = {
###
Find all node_definitions that have both on_timer and on_construct:
//lua local n = 0 for k,v in pairs(minetest.registered_nodes) do if (v.on_construct and v.on_timer) then n = n + 1 core.chat_send_all(n .. "=" .. dump(k)) end end
Result: 758
Find all node_definitions that have on_construct:
//lua local n = 0 for k,v in pairs(minetest.registered_nodes) do if (v.on_construct) then n = n + 1 core.chat_send_all(n .. "=" .. dump(k)) end end
Result: 1269
Find all node_definitions that have on_timer:
//lua local n = 0 for k,v in pairs(minetest.registered_nodes) do if (v.on_timer) then n = n + 1 core.chat_send_all(n .. "=" .. dump(k)) end end
Result: 916
###
Future update where we have random duration:
-- Preparation for random duration