Add register_on_nodeload()

This commit is contained in:
LoneWolfHT 2020-08-14 14:05:55 -07:00
parent a654b9b748
commit 12ab6213f3
2 changed files with 20 additions and 1 deletions

7
mods/nodes/api.md Normal file
View File

@ -0,0 +1,7 @@
# Node mod API
```lua
nodes.register_on_nodeload(function(pos, node)
-- Do stuff to a schematic node after it's been constructed for the first time
end)
```

View File

@ -1,4 +1,10 @@
nodes = {}
nodes = {
registered_on_loadnode = {}
}
function nodes.register_on_nodeload(func)
table.insert(nodes.registered_on_loadnode, func)
end
minetest.register_lbm({ -- Loads nodes placed by schematics that have meta
label = "Load special nodes placed by schematics",
@ -9,6 +15,12 @@ minetest.register_lbm({ -- Loads nodes placed by schematics that have meta
if minetest.get_meta(pos):get_int("loaded") ~= 0 then return end -- Already loaded
minetest.registered_nodes[node.name].on_construct(pos)
for _, func in ipairs(nodes.registered_on_loadnode) do
if func(pos, node) then
break
end
end
end
})